Solved

Validation for textbox that shows when radiobutton = "Other"

Posted on 2006-11-21
7
1,076 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
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
This video discusses moving either the default database or any database to a new volume.
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

762 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

23 Experts available now in Live!

Get 1:1 Help Now