Solved

Validation for textbox that shows when radiobutton = "Other"

Posted on 2006-11-21
7
1,077 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
  • 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Calling web service and its methods dynamically 2 37
Adjust the position 3 45
Asp.net mvc foreach 3 32
Class object 2 26
This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

929 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now