views:

1953

answers:

2

Hi,

I have an asp button on my page, in the Page_Load on the code behind, I am binding some javascript calls as follows.

btnExample.OnClientClicking = "functionOne(1,2);"+"function2()";

The problem is I would like to be able to pass the EventArgs passed to the Page_Load as in function2() I wish to call...

eventArgs.set_cancel(true).

Would appreciate any help.

+1  A: 

As far as I am able to understand your question, you can write "return false;" in function2().
This will also ensures that server side click event of btnExample will not gets fired.

Sachin Gaur
Hey, thanks for the suggestion. However, return false does not work, it still skips server side.
"skips to server side" I mean. Typo.
+1  A: 

If you are trying to prevent the post back, Sachin is correct you must return false. Don't forget that in addition to adding return false to your JavaScript function you must also add return when assigning 'OnClientClick'.

Code Behind:

btnExample.OnClientClick = "functionOne(1,2); return function2();";

JavaScript:

function function2()
{
    //Do something
    return false;
}
Phaedrus
Cheers, you are correct. Thank you (and Sachin as well).