Custom Validators...

P

Pai

I have a radio button server side control and a text box server side
control and an a Custom validator control placed on a .apsx page.

I have set the ControlToValidate Property of the Custom Validator
Control to the textbox and set the OnServerValidate method of the
Custom validator to CheckOtherDisease function as below:

<asp:CustomValidator id="CustomValidator2" style="Z-INDEX: 141; LEFT:
544px; POSITION: absolute; TOP: 488px" runat="server" Width="274px"
ControlToValidate="textOtherDisease" ErrorMessage="Enter Valid
Disease"
OnServerValidate="CheckOtherDisease"></asp:CustomValidator>

now when I select the radio button and no text is entered in the
textbox I need a error message to be prompted for the user as
mentioned in the CustomValidator Control

following is the code for the function CheckOtherDisease

public void CheckOtherDisease(object sender, ServerValidateEventArgs
args)
{
string my_disease_default = "";

if (rbnOtherDisease.Checked )
{
if (textOtherDisease.Text.CompareTo(my_disease_default) ==
0)
{
args.IsValid = false;
}
else
{
args.IsValid = true;
}
}
else
{
args.IsValid = true;
}
}

The same doesn't work...

Any help or suggestion would be appreciated.


Kind Regards,
Srikanth Pai.
 
T

Teemu Keiski

Because validation happens on server-side with OnServerValidate, you need to
cause a postback to trigger it (from the radiobutton) and also for it to
work as expected before critical code relying on the validation is run, you
need to check Page.IsValid property. Have you done these?

You can also create client-side code to trigger the validation, but it needs
bit js to be done. Details can be found in this article:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnaspp/html/aspplusvalid.asp

--
Teemu Keiski
MCP,Designer/Developer
Mansoft tietotekniikka Oy
http://www.mansoft.fi

AspInsiders Member, www.aspinsiders.com
ASP.NET Forums Moderator, www.asp.net
AspAlliance Columnist, www.aspalliance.com
 
S

Srikanth Pai

Hi Teemu Keiski,

I have done all that, If i remove this CustomValidator and add it to
another control it works?

I am not able to get this right why so?

any ideas?

Kind Regards,
Srikanth Pai
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,983
Messages
2,570,187
Members
46,747
Latest member
jojoBizaroo

Latest Threads

Top