CustomValidator added at runtime --> server-side validation dropped

P

peshrad

Hi !

I'm using Visual Studio 2000,
Win2K, IE 6, .NET 1.1.

I'm experimenting with an extremely simple ASP.NET web application.

When I add a CustomValidator to the designer by drag&drop,
I can accomplish both client-side and subsequent server-side validation.
At run-time, when I press my submit button,
first my JavaScript function is called for validation,
later my C# event handler is called in the server-side code.

However, when I add the CustomValidator at run-time,
only client-side validation works.

How can I fix this problem ?
Here comes the code that creates the CustomValidator at run-time.
The function cv_2_ServerValidate is never called later.

private void Page_Load(object sender, System.EventArgs e)
{
if(!IsPostBack)
{
CustomValidator cv = new CustomValidator();

cv.ID = "cv_2";
cv.ControlToValidate = "TextBox1";
cv.ErrorMessage = "Another input error!";
cv.ServerValidate +=new
ServerValidateEventHandler(cv_2_ServerValidate);
cv.ClientValidationFunction = "doClientValidation";

TextBox1.Parent.Controls.Add(cv);
}
}

Your kind advice would be appreciated.

Peter
 
P

peshrad

private void Page_Load(object sender, System.EventArgs e)
{
if(!IsPostBack)
{
CustomValidator cv = new CustomValidator();

cv.ID = "cv_2";
cv.ControlToValidate = "TextBox1";
cv.ErrorMessage = "Another input error!";
cv.ServerValidate +=new
ServerValidateEventHandler(cv_2_ServerValidate);
cv.ClientValidationFunction = "doClientValidation";

TextBox1.Parent.Controls.Add(cv);
}
}

Just drop the condition !IsPostBack
for executing the set-up of the CustomValidator !
 

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

Forum statistics

Threads
474,137
Messages
2,570,797
Members
47,342
Latest member
eixataze

Latest Threads

Top