|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Require text entry - only if radio button checkedHi;
I have a case where I need to require a TextBox be filled in only if a certain radio button is checked. I can't use RequiredFieldValidator because if the button is not checked, then it can be empty. But a CustomValidator.OnServerValidate is not called if a TextBox is empty. How should I handle this? -- thanks - dave david_at_windward_dot_net http://www.windwardreports.com see the "too much free time video" - http://www.windwardreports.com/film.htm hi David, theres a new property for asp.net 2.0 supported by the
customvalidator control, which you can set to have it validate an empty textbox control. The property you want to enable is : ValidateEmptyText="true" http://msdn2.microsoft.com/en-us/library/system.web.ui.webcontrols.customvalidator.validateemptytext.aspx Regards, Alessandro Zifiglio http://www.AsyncUI.net Show quoteHide quote "David Thielen" <thielen@nospam.nospam> ha scritto nel messaggio news:F0BF6EA9-9479-4A71-805C-FC3CCC78991A@microsoft.com... > Hi; > > I have a case where I need to require a TextBox be filled in only if a > certain radio button is checked. I can't use RequiredFieldValidator > because > if the button is not checked, then it can be empty. But a > CustomValidator.OnServerValidate is not called if a TextBox is empty. > > How should I handle this? > > -- > thanks - dave > david_at_windward_dot_net > http://www.windwardreports.com > > see the "too much free time video" - > http://www.windwardreports.com/film.htm > > Thanks for Alessandro's input.
Hi Dave, Does the "ValidateEmptyText" property the one you need? Please feel free to post here if you have any further questions. Sincerely, Steven Cheng Microsoft MSDN Online Support Lead This posting is provided "AS IS" with no warranties, and confers no rights. that was it - thank you
-- Show quoteHide quotethanks - dave david_at_windward_dot_net http://www.windwardreports.com Cubicle Wars - http://www.windwardreports.com/film.htm "Steven Cheng[MSFT]" wrote: > Thanks for Alessandro's input. > > Hi Dave, > > Does the "ValidateEmptyText" property the one you need? Please feel free > to post here if you have any further questions. > > Sincerely, > > Steven Cheng > > Microsoft MSDN Online Support Lead > > > This posting is provided "AS IS" with no warranties, and confers no rights. > > You could also enable/disable the RequieredValidator by using a short
clientSide snippet. Something like radioButton.Attributes["onchange"] = string.Format("ValidatorEnable(document.getElementById('{0}'),_ document.getElementById('{1}').checked);",requiredValidator.ClientID,radioButton.ClientID); Regards, Tasos David Thielen wrote: Show quoteHide quote > Hi; > > I have a case where I need to require a TextBox be filled in only if a > certain radio button is checked. I can't use RequiredFieldValidator because > if the button is not checked, then it can be empty. But a > CustomValidator.OnServerValidate is not called if a TextBox is empty. > > How should I handle this? > > -- > thanks - dave > david_at_windward_dot_net > http://www.windwardreports.com > > see the "too much free time video" - http://www.windwardreports.com/film.htm Hi David, Steven and Alessandro and Tasos,
I have a similar question and please be patient as I am very new to .net... I want to require a textbox field to have an entry only when a certain selection is made from a dropdown list. For example: The form is asking for agency name and I have a pre-populated list of agency names with the last option being "Other" - if the user selects "other" then I want the Other Agency: textbox field to be required. I have started a customvalidator control but I just can't get it to work yet. Here is what I have: <asp:CustomValidator id="agencynamevalidator" Runat="server" ControlToValidate="otheragency" OnServerValidate="ServerValidate" validateemptytext="true" display="Static" ErrorMessage="You chose other because your agency does not appear on this list, please enter the name of your agency."> *</asp:customvalidator> 'if value of agency field is equal to Other then make the otheragency field required Private Sub agencynamevalidator_ServerValidate(ByVal source As System.Object, ByVal args As System.WEb.UI.WebControls.ServerValidateEventArgs) Handles agencynamevalidator.ServerValidate Try If request.form(agency.value) is "Other" And request.form(otheragency.text) is not "" then args.IsValid = true ElseIf request.form(agency.value) is "Other" And request.form(otheragency.text) is "" then args.IsValid = (otheragency.text.trim() <> "") Else args.IsValid = false End If Catch ex As Exception 'whatever End Try End Sub Right now - I get the following error message: Compiler Error Message: BC30506: Handles clause requires a WithEvents variable. Show quoteHide quote "David Thielen" wrote: > Hi; > > I have a case where I need to require a TextBox be filled in only if a > certain radio button is checked. I can't use RequiredFieldValidator because > if the button is not checked, then it can be empty. But a > CustomValidator.OnServerValidate is not called if a TextBox is empty. > > How should I handle this? > > -- > thanks - dave > david_at_windward_dot_net > http://www.windwardreports.com > > see the "too much free time video" - http://www.windwardreports.com/film.htm > >
WebForm UserControl ?s
Firing events for child controls inside a DataGrid ItemDataBound fires for header only Custom Server Control Problem with HTML in ASP.Net App CustomValidator Retireve data with SqlDatasource & dynamically manipulate before dispalying Can a Repeater control repeat an .ascx? ASP.NET vs Windows Forms for building client application asp:menu dynamichoverstyle backcolor does not work.. |
|||||||||||||||||||||||