Hi all,
I have a asp.net form, inside has a webcombo, I placed a requiredfieldvalidator and want to validate it, but cannot choose the webcombo control inside the requirefieldvalidator.
Can you suggest me how to ensure user choose a value in webcombo before submit the form?
Thank you very much for your help! Happy new year!
The UltraWebCombo does not have the typical attribute of a control such as:
[ValidationProperty("DataValue")]
which enables a required field validator to work. In hindsight this makes sense because depending on your usage of the control (for instance, a user can type in free text) DisplayValue is correct versus DataValue. So, what you really want to do is use a custom validator on the webcombo. This gives you the latitude to interrogate whichever attribute is your (mental) appropriate Validation Property of interest.
Thanks for your reply!
But I tried to place a customvalidator in the asp.net page. But in the customvalidator cannot chooose the webcombo in "ControlToValidate" value. Can you teach me how to make it work? Thanks!
Ah, for a CustomValidator ControlToValidate is not required or necessary:
<asp:CustomValidator ID="cvList" runat="server" ErrorMessage="List is a required field" EnableClientScript="False" Text="*" Enabled="True" OnServerValidate="cvList_ServerValidate"></asp:CustomValidator>
protected void cvList_ServerValidate_ServerValidate(object source, ServerValidateEventArgs e) {
//Check anything that is appropriate (note control does not have to be passed in)
if (iddlList.SelectedRow.Cells[1].Text != "M") { e.IsValid = false; } }
Thanks. So must validate the field after post back? Cannot check in client side?
I am running into an issue where I am trying to validate more than 1 webcombo
I think the issue is that the customvalidator is not tied to the control. So having multiple customvalidators doesn't work.
any ideas?
Thanks kuldeepvija, this works fine(don't forget to set EnableClientScript to True if you disabled it)
{
}
<asp:CustomValidator ID="cvPortName" runat="server" ErrorMessage="Please select a Port" ClientValidationFunction="ValidatePort" Display="None"></asp:CustomValidator>
This works fine for me, see if it helps you.
Happy coding
You can use basic HTML/Javascript
Just use a JavaScript onSubmit event handler, check any value in the control you want and either return true and let the submit happen or return false and provide a warning; you can use a simple alert box or use the Dom to write an error to the page.