Solved

Validating textbox when user clicks Yes in radiobutton

Posted on 2010-08-25
1
432 Views
Last Modified: 2012-05-10
I have a repeater. In it, I have a radiobutton list and a textbox.

Radiobutton list has "Yes" and "No". If user clicks "Yes", they have to enter something in the textbox. They can't leave it empty.

I don't think a requiredfieldvalidator would work here. How can I do this??
<asp:Repeater runat="server" OnItemDataBound="rpQuestions_OnItemDataBound"   ID="rpQuestions">
              <ItemTemplate>
              <tr>
              <td>
                <asp:Label runat="server" ID="lblId" Visible="false" Text='<%# DataBinder.Eval(Container.DataItem, "QuestionId") %>'></asp:Label>
              </td>
              
               <td  align="right">
               
                
                 <asp:RadioButtonList   runat="server" ID="rbQuestions"  TextAlign="Right" RepeatDirection="Horizontal">
                   <asp:ListItem Value="Y"  Text="Yes"></asp:ListItem>
                   <asp:ListItem Value="N" Text="No"></asp:ListItem>
                 </asp:RadioButtonList>
               
                   
                 <asp:RequiredFieldValidator ID="RequiredFieldValidator10" Display="Dynamic" ControlToValidate="rbQuestions" ErrorMessage="Employment Questions" Text="*" runat="server"></asp:RequiredFieldValidator>     
               
                </td>
              </tr>
              <tr>
              <td></td>
              <td><asp:Label ID="lblExplain" Text='<%# DataBinder.Eval(Container.DataItem, "Explain") %>' runat="server" ></asp:Label></td>
               <td>
                 <asp:TextBox runat="server"   ID="txtExplanation"  TextMode="MultiLine"></asp:TextBox>
               </td>
              </tr>
            </ItemTemplate>
        </asp:Repeater>

Open in new window

0
Comment
Question by:Camillia
1 Comment
 
LVL 16

Accepted Solution

by:
Vikram Singh Saini earned 500 total points
ID: 33525450
Hi,

There is a property named ValidateEmptyText for custom validation of textbox. More details on link: http://quickstarts.asp.net/QuickStartv20/aspnet/doc/validation/default.aspx#validateemptytext

Regards,
VSS

0

Featured Post

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!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
No Data for DropDown List 2 32
How can I run RAW complex query's with Entity Framework Core 1 66
Problem to copy file 14 46
Aspx calendar pop up control 3 27
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…
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…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

763 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