Solved

Validation for textbox that shows when radiobutton = "Other"

Posted on 2006-11-21
7
1,080 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
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 
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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
asp day pilot 3 23
tutorial for ebay api 3 55
Jquery datatables integration with ASP.NET MVC, bootstrap 3 22
Where is this file? 3 25
In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

861 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