Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Validation for textbox that shows when radiobutton = "Other"

Posted on 2006-11-21
7
Medium Priority
?
1,089 Views
Last Modified: 2008-01-09
Hello All,

I decided to start from scratch on my validation as I've been searching for two days now and can't figure it out.

I have a form with multiple radio button groups.

Some of the groups have a radiobutton listvalue of "Other"

    <asp:RadioButtonList ID="radio6" runat="server" AutoPostBack="true" OnSelectedIndexChanged="showOther6">
    <asp:ListItem Text="Friendly" Value="Friendly" />
    <asp:ListItem Text="Helpful" Value="Helpful" />
    <asp:ListItem Text="Private & respectful" Value="Private & respectful" />
    <asp:ListItem Text="Pushy" Value="Pushy" />
    <asp:ListItem Text="Lacking in privacy" Value="Lacking in privacy" />    
    <asp:ListItem Text="Other" Value="Other" />
    </asp:RadioButtonList>    
     <asp:Panel id="span6" runat="server" visible="false">(please specify) <asp:TextBox runat="server" ID="txt6Other" /></asp:Panel>
     <asp:RequiredFieldValidator ControlToValidate="radio6" ID="val6" runat="server" ErrorMessage="*Required" />
This validator check the radiobuttonlist group.

If the value is other, I show a textbox like this:

    Protected Sub showOther6(ByVal sender As Object, ByVal e As System.EventArgs)
        If radio6.SelectedValue.ToString = "Other" Then
            span6.Visible = True
        Else
            span6.Visible = False
        End If
    End Sub

All of the above works fine.

I need to add validation to check that if the "other" is selected that there is also a check on the txt6Other.Text to make sure it's not blank.

Any help to solve this would be greatly  appreciated as I think I'm going in circles.

Cheers
Don

0
Comment
Question by:donaldcroswell
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
7 Comments
 
LVL 6

Assisted Solution

by:badalpatel
badalpatel earned 1000 total points
ID: 17993248
u just have to add one more requiredfieldvalidator in ur panel span6..i think that will do it..and if u want to do this with javascript then tell me i will help u out...

 <asp:Panel id="span6" runat="server" visible="false">(please specify) <asp:TextBox runat="server" ID="txt6Other" />
                     <asp:RequiredFieldValidator ControlToValidate="txt6Other" ID="RequiredFieldValidator1" runat="server" ErrorMessage="*Required" />
                     </asp:Panel>
0
 
LVL 12

Accepted Solution

by:
sandip132 earned 1000 total points
ID: 17993354
add this in Panel tag:

<asp:RequiredFieldValidator id="RequiredFieldValidator1" runat="server" ErrorMessage="Please enter value."
                              ControlToValidate="txt2Other" Enabled="False"></asp:RequiredFieldValidator>

Protected Sub showOther6(ByVal sender As Object, ByVal e As System.EventArgs)
        If radio6.SelectedValue.ToString = "Other" Then
            span6.Visible = True
            RequiredFieldValidator1.Enabled = True  '<<'''''''''''''''''''''''''''''''''''''''''''''''''''' Enable the validator here.
        Else
            span6.Visible = False
        End If
 End Sub
0
 

Author Comment

by:donaldcroswell
ID: 17993615
Hey Guy

Thanks!

I've got the boxes working and validating but...

Occasionally it will cause IE to crash with this error.

The instruction at "0x7470b493" referenced at "0x7470b493" . The memory could not be "read".
Click on OK to terminate the program.

My steps to cause it to crash are....

Fill in all questions but leave one group with "other" empty
(this causes that group to validate with red warning)
Go to that group and fill in the "other" radio button
(this causes the panel to show with the text box for other)
Hit submit to test the validation on the text box for other
(this causes the above error)

I need this to work with no errors.

Any ideas why it is falling over or how to find out why?

Cheers
Don
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 6

Expert Comment

by:badalpatel
ID: 17993626
i dont think its a code error..
anyway just try to reboot ur system and check if the error is still there??
0
 

Author Comment

by:donaldcroswell
ID: 17993725
Yup it's still there...

I guess I'll have to try on another machine.
0
 
LVL 12

Expert Comment

by:sandip132
ID: 17994124
yes... I think we had one EE session for this.. :)

http://www.experts-exchange.com/Programming/Programming_Languages/Dot_Net/ASP_DOT_NET/Q_22066228.html

dont worry about your code... it should work fine. Need to re-install the appli./(IE) where the exception is occuring.
0
 

Author Comment

by:donaldcroswell
ID: 17998757
Hey sandip,

yeah, in that discussion your change to panel seemed to fix my problem but then is started to occur again.

I'll just reinstall it.

Cheers
Don
0

Featured Post

Tech or Treat!

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Suggested Courses

618 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question