954,560 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

validating a textbox without using validation control

I have 3 textboxes in my webform.I want my user to enter valid entries into them. If user leaves any textbox empty.I want Give him an alert to him (like a msgbox in vb.net).I'm using textboxes in asp.net(web server controls).I dont want to use the validation controls as they wont give a pop up message.

ramareddy_dotne
Newbie Poster
15 posts since May 2005
Reputation Points: 10
Solved Threads: 0
 

in the submit button do something like

if (txtField1.Text = "")
{
msgbox = "Sorry please enter something in txtFeild1";
}

Try something like that.

percent20
Light Poster
33 posts since Jan 2005
Reputation Points: 12
Solved Threads: 0
 

percent20's coding is not working in the asp.net server.This is the correct code and WHICH IS WORKING ONLY WITH c#Make sure this lable1 is disabled the visible properties in the properties

if (txtField1.Text =="")
                 { label1.Visible = true; 
                }
kasun.u
Newbie Poster
2 posts since Jun 2010
Reputation Points: 10
Solved Threads: 0
 
I have 3 textboxes in my webform.I want my user to enter valid entries into them. If user leaves any textbox empty.I want Give him an alert to him (like a msgbox in vb.net).I'm using textboxes in asp.net(web server controls).I dont want to use the validation controls as they wont give a pop up message.

Hi Rama
You have mentioned a specific reason "they wont give a pop up message" is this the reason why you are not using validation controls?

Validation Control are performed on client side n therefore good user experience, on the other hand you have server side validation which you can write a peiece of code to validate controls . you just have set display="None", which gives you pop up message.

client validation control

<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("Qty") %>' Width="50px" MaxLength="3" AutoPostBack="True" OnTextChanged="TextBox1_TextChanged"></asp:TextBox>
                            <asp:RequiredFieldValidator ID="RequiredFieldValidator1" 
                            runat="server" 
                            ErrorMessage="You must enter Qty" 
                            ValidationGroup="v1" 
                            ControlToValidate="TextBox1" Display="None" SetFocusOnError="true"  >

<asp:ValidationSummary ID="ValidationSummary1" runat="server" ShowSummary="false" ShowMessageBox="true" ValidationGroup="v1" />

Mark as solved if it helps you!!!

reach_yousuf
Junior Poster
195 posts since Sep 2007
Reputation Points: 12
Solved Threads: 38
 

use javascript and Regx...
one and the same thing..

dnanetwork
Practically a Master Poster
Banned
633 posts since May 2008
Reputation Points: 28
Solved Threads: 106
 
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("Qty") %>' Width="50px" MaxLength="3" AutoPostBack="True" OnTextChanged="TextBox1_TextChanged"></asp:TextBox>                            <asp:RequiredFieldValidator ID="RequiredFieldValidator1"                             runat="server"                             ErrorMessage="You must enter Qty"                             ValidationGroup="v1"                             ControlToValidate="TextBox1" Display="None" SetFocusOnError="true"  > <asp:ValidationSummary ID="ValidationSummary1" runat="server" ShowSummary="false" ShowMessageBox="true" ValidationGroup="v1" /><asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("Qty") %>' Width="50px" MaxLength="3" AutoPostBack="True" OnTextChanged="TextBox1_TextChanged"></asp:TextBox>
                            <asp:RequiredFieldValidator ID="RequiredFieldValidator1" 
                            runat="server" 
                            ErrorMessage="You must enter Qty" 
                            ValidationGroup="v1" 
                            ControlToValidate="TextBox1" Display="None" SetFocusOnError="true"  >

<asp:ValidationSummary ID="ValidationSummary1" runat="server" ShowSummary="false" ShowMessageBox="true" ValidationGroup="v1" />
shahnawaz khan
Newbie Poster
1 post since Jan 2011
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You