May 08, 2003 12:05 AM
Hook Client Events to Server Controls
Pick up three quick techniques to fire up server controls from the client side.
DevConnections
Rating:

(0)
UI Tip
LANGUAGES:JavaScript | C#
TECHNOLOGIES:Client Events | Server Controls
Hook Client Events to Server Controls
Pick up three quick techniques to fire up servercontrols from the client side.
By Brad McCabe
Looking to hook client events to server controls? Well,you can take a variety of approaches. The easiest is when the control doesn'thave a server event with the same name. All you need to do is put the clientevent on the tag:
<asp:Image onMouseOver="alert('Mouse Over')" .../>"
For objects, as a button, you can hook them to clientevents by adding attributes from your server-side code. This is some basic codeyou might add in your page load event:
Button1.Attributes.Add("onclick","alert('Clicked');")
If you need to hook up to the form submission, or in theevent of validation cases, you can use the RegisterOnSubmitStatement in yourserver-side code. The following page load code snippet causes any control onthe page to display a JavaScript alert box before a submission or postback:
RegisterOnSubmitStatement("uniqueKey","alert('Submit!');")
You can use any one of these strategies to call moreadvanced JavaScript. Using the approach that fits your needs lets you performmore logic on the client side and reduce the overhead of postbacks in ASP.NET.
Brad McCabe is the technical evangelist forInfragistics. Brad also has been a systems architect and consultant for VerizonCommunications and many other clients, and he was a leading .NET evangelistwithin Ajilon Consulting. His primary interests include ASP.NET, Windows CE.NET, .NET Compact Framework, and Microsoft's networking technologies. E-mailhim at mailto:brad@infragistics.com.