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.

in the submit button do something like

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

Try something like that.

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; 
                }

Edited 6 Years Ago by kasun.u: n/a

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!!!

<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" />

Edited 5 Years Ago by Ezzaral: Added code tags. Please use them to format any code that you post.

This article has been dead for over six months. Start a new discussion instead.