Validation based on radio button selection

G

Gary W. Smith

Hello,

I have a simple form with a radio button group on it and I need to do
some basic validation based upon which button is checked. Here is a
little more detail.

if button one is selected, then we want to do validation on textbox
control one and no validation on textbox two. If button two is
selected, then we want to do validation on textbox control two and no
validation on textbox one.

Each textbox has its own regularexpressvalidation control as well as a
required field control. As such, when the users click on the first
radio button they can't continue because the second item has no value.

I would like to do this on the front end but I just don't have much
experience with javascript and its interaction with .net to make this
work.

Any help or real samples would be greatly appreciated.
 
M

Masudur

Hello,

I have a simple form with a radio button group on it and I need to do
some basic validation based upon which button is checked. Here is a
little more detail.

if button one is selected, then we want to do validation on textbox
control one and no validation on textbox two. If button two is
selected, then we want to do validation on textbox control two and no
validation on textbox one.

Each textbox has its own regularexpressvalidation control as well as a
required field control. As such, when the users click on the first
radio button they can't continue because the second item has no value.

I would like to do this on the front end but I just don't have much
experience with javascript and its interaction with .net to make this
work.

Any help or real samples would be greatly appreciated.

Hi...

here it goes...

in html....

<strong><span style="font-size: 24pt">Just For Test Things<br />
<br />
</span></strong>
<asp:RadioButtonList ID="RadioButtonList1" runat="server"
AutoPostBack="True"
OnSelectedIndexChanged="RadioButtonList1_SelectedIndexChanged"
RepeatDirection="Horizontal">
<asp:ListItem>Email</asp:ListItem>
<asp:ListItem>Phone</asp:ListItem>
</asp:RadioButtonList><br />
Email:<asp:TextBox ID="txtEmail" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="ERFV" runat="server"
ControlToValidate="txtEmail"
ErrorMessage="RequiredFieldValidator"></
asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="EREV" runat="server"
ControlToValidate="txtEmail"
ErrorMessage="RegularExpressionValidator"
ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"></
asp:RegularExpressionValidator><br />
<br />
Phone:<asp:TextBox ID="txtPhone" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="PRFV" runat="server"
ControlToValidate="txtPhone"
ErrorMessage="RequiredFieldValidator"></
asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="PREV" runat="server"
ControlToValidate="txtPhone"
ErrorMessage="RegularExpressionValidator"
ValidationExpression="((\(\d{3}\) ?)|(\d{3}-))?\d{3}-\d{4}"></
asp:RegularExpressionValidator>
<br />
<br />
<asp:Button ID="Button1" runat="server" Text="Button" />

and in code behind...

protected void RadioButtonList1_SelectedIndexChanged(object sender,
EventArgs e)
{
if (RadioButtonList1.SelectedIndex == 0)
{
PREV.Enabled = false;
PRFV.Enabled = false;

EREV.Enabled = true;
ERFV.Enabled = true;
}
else
{
EREV.Enabled = false;
ERFV.Enabled = false;

PREV.Enabled = true;
PRFV.Enabled = true;
}
}

Thanks
Md. Masudur Rahman (Munna)
Kaz Software Ltd.
www.kaz.com.bd
http://munnacs.110mb.com
 
G

Gary W. Smith

Hi...
here it goes...

in html....

<strong><span style="font-size: 24pt">Just For Test Things<br />
<br />
</span></strong>
<asp:RadioButtonList ID="RadioButtonList1" runat="server"
AutoPostBack="True"
OnSelectedIndexChanged="RadioButtonList1_SelectedIndexChanged"
RepeatDirection="Horizontal">
<asp:ListItem>Email</asp:ListItem>
<asp:ListItem>Phone</asp:ListItem>
</asp:RadioButtonList><br />
Email:<asp:TextBox ID="txtEmail" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="ERFV" runat="server"
ControlToValidate="txtEmail"
ErrorMessage="RequiredFieldValidator"></
asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="EREV" runat="server"
ControlToValidate="txtEmail"
ErrorMessage="RegularExpressionValidator"
ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"></
asp:RegularExpressionValidator><br />
<br />
Phone:<asp:TextBox ID="txtPhone" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="PRFV" runat="server"
ControlToValidate="txtPhone"
ErrorMessage="RequiredFieldValidator"></
asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="PREV" runat="server"
ControlToValidate="txtPhone"
ErrorMessage="RegularExpressionValidator"
ValidationExpression="((\(\d{3}\) ?)|(\d{3}-))?\d{3}-\d{4}"></
asp:RegularExpressionValidator>
<br />
<br />
<asp:Button ID="Button1" runat="server" Text="Button" />

and in code behind...

protected void RadioButtonList1_SelectedIndexChanged(object sender,
EventArgs e)
{
if (RadioButtonList1.SelectedIndex == 0)
{
PREV.Enabled = false;
PRFV.Enabled = false;

EREV.Enabled = true;
ERFV.Enabled = true;
}
else
{
EREV.Enabled = false;
ERFV.Enabled = false;

PREV.Enabled = true;
PRFV.Enabled = true;
}
}

Thanks
Md. Masudur Rahman (Munna)
Kaz Software Ltd.www.kaz.com.bdhttp://munnacs.110mb.com- Hide quoted text -

- Show quoted text -

Munna,

We are currently doing something similar. I was hoping to prevent the
user from having to do a full post back to validate BUT that works, so
we'll stick with it.

Thanks,

Gary Wayne Smith
 

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

Forum statistics

Threads
473,755
Messages
2,569,534
Members
45,007
Latest member
obedient dusk

Latest Threads

Top