Change the RegularExpressionValidator's ValidationExpression at cl

A

Andy Eshtry

I have a radio button list, a textbox representing SIN or EIN based on my radio button list selection so I put 2 regularexpressionvalidator to evaluate the value of textbox.

EIN must be (for simplicity) with this format (2 digits) like 12 (ValidationExpression="\d{3}-\d{2}")

and SIN must be (for simplicity) with this format (3digits-2digits) like 123-45 (ValidationExpression="\d{3}-\d{2}")

It works well. The problem is: When I change the redio buttons selection, I do not want page to be refreshed. What is the right way?

I have used Microsoft validation controls in all pages so I want to generate the same format error message if I need to bypass the validations controls.

I put all the aspx.cs and asp code at the end of this email.

Please help. Thanks for your help.

Regards

Andy Eshterayeh



This is the ASPX.CS file

private void RadioButtonList1_SelectedIndexChanged(object sender, System.EventArgs e)

{


if(RadioButtonList1.SelectedValue.Equals("1")) //THIS IS EIN

{


ExpSSN.Enabled = false;

ExpSSN.Visible = false;



ExpEIN.Enabled = true;

ExpEIN.Visible = true;

}

if(RadioButtonList1.SelectedValue.Equals("2")) //THIS IS SSN

{


ExpEIN.Enabled = false;

ExpEIN.Visible = false;


ExpSSN.Enabled = true;

ExpSSN.Visible = true;

}



}

private void Button1_Click(object sender, System.EventArgs e)

{

Response.Redirect("rblist.aspx");

}

This is the ASPX file

<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<asp:RadioButtonList id="RadioButtonList1" style="Z-INDEX: 101; LEFT: 264px; POSITION: absolute; TOP: 192px"
runat="server" AutoPostBack="True" RepeatDirection="Horizontal" Width="376px">
<asp:ListItem Value="1">EIN (12)</asp:ListItem>
<asp:ListItem Value="2">SSN(123-45)</asp:ListItem>
</asp:RadioButtonList>
<asp:validationsummary id="valfrmCustomerInfo" style="Z-INDEX: 107; LEFT: 352px; POSITION: absolute; TOP: 96px"
Runat="server" DisplayMode="BulletList" ForeColor="#ff0066"></asp:validationsummary>
<asp:requiredfieldvalidator id="ReqSSNEINRbtn" style="Z-INDEX: 106; LEFT: 192px; POSITION: absolute; TOP: 256px"
runat="server" ControlToValidate="RadioButtonList1" Display="None" ErrorMessage="Please select SSN or EIN Number "></asp:requiredfieldvalidator>
<asp:regularexpressionvalidator id="ExpSSN" style="Z-INDEX: 104; LEFT: 200px; POSITION: absolute; TOP: 328px" ControlToValidate="TextBox1"
Display="None" ErrorMessage="Please fill in a valid SSN Number" Enabled="False" ValidationExpression="\d{3}-\d{2}"
Visible="False" Runat="server">Please fill in a valid SSN Number</asp:regularexpressionvalidator>
<asp:Button id="Button1" style="Z-INDEX: 102; LEFT: 440px; POSITION: absolute; TOP: 376px" runat="server"
Text="Button"></asp:Button>
<asp:TextBox id="TextBox1" style="Z-INDEX: 103; LEFT: 376px; POSITION: absolute; TOP: 256px"
runat="server"></asp:TextBox>
<asp:regularexpressionvalidator id="ExpEIN" style="Z-INDEX: 105; LEFT: 192px; POSITION: absolute; TOP: 296px" runat="server"
ControlToValidate="TextBox1" Display="None" ErrorMessage="Please enter a valid EIN Number" Enabled="False" ValidationExpression="\d{2}"
Visible="False">Please enter a valid EIN Number</asp:regularexpressionvalidator>
</form>
</body>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,817
Latest member
DicWeils

Latest Threads

Top