2 errors displayin at same time-why [Resolved]

Posted by Oswaldlily under ASP.NET on 3/30/2012 | Points: 10 | Views : 809 | Status : [Member] | Replies : 3
protected void btnImport_Click(object sender, EventArgs e)
{
if(textbox1.text="")
{
label1.text="should not be empty";
}
else if(dropdownlis.selectedvalue=="Select")
{
label2.text="Plz select any 1 value";
}
}
when first time click import one error displayin
when i click second time "both" errors displayin even if one is correct.
What could be the reason??




Responses

Posted by: Prabhakar on: 3/30/2012 [Member] [MVP] Starter | Points: 50

Up
0
Down

Resolved
Hi Oswaldlily


Firstly Correct ur code now and show ur error if .. error comes


protected void btnImport_Click(object sender, EventArgs e)

{
if(textbox1.text == "")
{
label1.text="should not be empty";
}
else if(dropdownlis.selecteitem.Tostring() == "Select")
{
label2.text="Plz select any 1 value";
}
}


Best Regard's
Prabhakar

Oswaldlily, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Rajni.Shekhar on: 3/30/2012 [Member] Bronze | Points: 25

Up
0
Down
protected void btnImport_Click(object sender, EventArgs e)
{
if(textbox1.text == "")
{
label1.text="should not be empty";
label2.text="";
}
else if(dropdownlis.selecteitem.Tostring() == "Select")
{
label1.text="";
label2.text="Plz select any 1 value";
}
}



Thanks,
Rajni Shekhar

Oswaldlily, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: perfectchourasia-9163 on: 4/3/2012 [Member] Starter | Points: 25

Up
0
Down




<form id="form1" runat="server">

<fieldset id="personal" class="fielsetclass">
<asp:Label ID="lblmess" runat="server" style="color:Red;">* All Fields are mandatory.</asp:Label><br /><br />
<legend class="legendcss">Search</legend>

<asp:Label ID="lblorderid" Text=" Order Id :" runat="server" CssClass="labelclass"></asp:Label>
<asp:TextBox ID="txtorderid" runat="server" TabIndex="1"></asp:TextBox>
<asp:RequiredFieldValidator id="vrOrderid" runat="server" ControlToValidate="txtorderid" ErrorMessage="*" Display="dynamic" ValidationGroup="a">*</asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ControlToValidate="txtorderid" ErrorMessage="Invalid Order Id" ValidationExpression="^\d+$" ValidationGroup="a"></asp:RegularExpressionValidator>

<br />
<asp:Label ID="lblcname" Text="Customer Name :" runat="server" CssClass="labelclass"></asp:Label>
<asp:TextBox ID="txtCname" runat="server" TabIndex="2"></asp:TextBox>
<asp:RequiredFieldValidator id="vrCname" runat="server" ControlToValidate="txtCname" ErrorMessage="Please enter your name!" Display="dynamic" ValidationGroup="a">*</asp:RequiredFieldValidator>

<br />
<asp:Label ID="lblemail" Text="Email Id :" runat="server" CssClass="labelclass"></asp:Label>
<asp:TextBox ID="txtemail" runat="server" TabIndex="3"></asp:TextBox>
<asp:RequiredFieldValidator id="RequiredFieldValidator1" runat="server" ControlToValidate="txtEmail" ErrorMessage="*" Display="dynamic" ValidationGroup="a">*</asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ValidationExpression="^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$" ID="rxpEmail" runat="server"
ErrorMessage="Email Address is not valid" Text="Input valid email address!" Display="Static" ControlToValidate="txtEmail" ValidationGroup="a"></asp:RegularExpressionValidator>

<br />
</fieldset>
<div align="center">
<asp:Button ID="btnsearch" runat="server" Text="Search" OnClick="btnsearch_Click" ValidationGroup="a" />
<asp:Button ID="btnreset" runat="server" Text="reset"
onclick="btnreset_Click" />
</div>
</div>
</form>
Here i have used validationgroup property

ER sandeep chourasia
sandeepchrs@yahoo.com (on facebook)
http://www.aspnetcodes.com/

Oswaldlily, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response