Modify the builtin onclick event of button?


C

Caspy

When add a button to a web form, if the button can CauseValidation, the
server emits client side javascript as:
<input type="submit" name="Button1" value="Button"
onclick="if (typeof(Page_ClientValidate) == 'function')
Page_ClientValidate(); "
language="javascript" id="Button1" />

What I want to let the emitted javascript like :
<input type="submit" name="Button1" value="Button"
onclick="if (typeof(Page_ClientValidate) == 'function')
Page_ClientValidate();
if (Page_IsValid !=null && Page_IsValid == true)
DoSomethingIWant();"
language="javascript" id="Button1" />

If I override the Render() method, the buildin jscript always emitted. How
can I get the exactly I want above?

Thanks in advance.
 
Ad

Advertisements

R

Raul Macias

You can add an onclick event handler to the button like this:

Button1.Attributes.Add("onclick", "if (Page_IsValid !=null && Page_IsValid
== true) DoSomethingIWant();");
 
Ad

Advertisements

C

Caspy

You approach generates something like:
<input type="submit" name="Button1" value="Button" onclick="if(Page_IsValid
== fasle) alert('Invalid!');if (typeof(Page_ClientValidate) == 'function')
Page_ClientValidate(); " language="javascript" id="Button1" />

The key point here is that (Page_IsValid == fasle) is checked before the
page is validated, which the Page_IsValid always true. This is not waht I
want.
 

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

Top