Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / August 2007

Tip: Looking for answers? Try searching our database.

Validation based on radio button selection

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Gary W. Smith - 30 Jul 2007 00:29 GMT
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.
Masudur - 30 Jul 2007 08:04 GMT
On Jul 30, 5:29 am, "Gary W. Smith" <gary.sm...@primeexalia.com>
wrote:
> Hello,
>
[quoted text clipped - 16 lines]
>
> 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
Gary W. Smith - 03 Aug 2007 22:15 GMT
> Hi...
>
[quoted text clipped - 65 lines]
>
> - 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

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.