A
Assimalyst
Hi,
I am trying to write some server side validator code in C#. I want to
have a piece of code that can be used by all DropDownLists on a
webform, giving a false value if the SelectedIndex is 0.
Here's the code:
protected void serverValidateCboBx(object source,
ServerValidateEventArgs args)
{
DropDownList dl =
FindControl(((CustomValiator)(source)).ControlToValidate);
if(dl.SelectedIndex == 0)
{
args.IsValid = false;
}
else
{
args.IsValid = true;
}
}
But i get the build error
Cannot implicitly convert type 'System.Web.UI.Control' to
'System.Web.UI.WebControls.DropDownList'
and the FindControl syntax is underlined.
Any suggestions on ways to solve this?
Thanks
I am trying to write some server side validator code in C#. I want to
have a piece of code that can be used by all DropDownLists on a
webform, giving a false value if the SelectedIndex is 0.
Here's the code:
protected void serverValidateCboBx(object source,
ServerValidateEventArgs args)
{
DropDownList dl =
FindControl(((CustomValiator)(source)).ControlToValidate);
if(dl.SelectedIndex == 0)
{
args.IsValid = false;
}
else
{
args.IsValid = true;
}
}
But i get the build error
Cannot implicitly convert type 'System.Web.UI.Control' to
'System.Web.UI.WebControls.DropDownList'
and the FindControl syntax is underlined.
Any suggestions on ways to solve this?
Thanks