Saturday, March 31, 2012

What is OnServerClick?

I would like to know what OnServerClick is. I normally use 'onclick=' which I thought was executed on the server when I have runat server attribute.Per thedocs:

OnServerClick raises the ServerClick event. This allows you to provide a custom handler for the event.

Thus handling the click event server-side. OnClick is interpreted client-side via JavaScript. See this web page for more info:

http://www.htmlgoodies.com/beyond/adv_js.html#click
Thanks - I presume this only applies to HTML buttons and not server controls. Can you have onclick and onserver click in a server control button ?
Correct, it only is available on HTML controls that support it.

If you want to add JavaScript to an asp.net webcontrol, you can do something like this:

myButton.Attributes.Add("OnClick", "return confirm('Did you really want to click me?')")
Thanks - that is most helpful

0 comments:

Post a Comment