Solved

Validation for textbox that shows when radiobutton = "Other"

Posted on 2006-11-21
7
1,081 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 250 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 250 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
Technology Partners: 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

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!

Question has a verified solution.

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

Suggested Solutions

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.

749 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