Client-side events fired in the browser window are added to HTML tags via attributes with
names such as onclick, onblur, onmouseover, onmouseout, and so on. The value of the eventhandling
attribute contains the script that you want to execute when the event is raised. The
following HTML snippet shows a
tag with an inline onclick event handler that pops up
an alert message box:
TopLabel
The browser is perfectly happy to execute this JavaScript when the tag is clicked.
The first server control example demonstrates how to add script code to an ASP.NET server
control to handle a client-side click event like the previous one. As an ASP.NET developer, you
have two options available to add the onclick event code to the server control:
??? You can add it declaratively via an attribute on the control??™s tag in the .aspx page.
??? You can add it programmatically to the Attributes collection of the server control in the
code-behind class.
Adding the code to the .aspx page is the simpler of the two options. Another way to add a
client-side click event handler is to encapsulate the script into a server control. The following
code shows how to generate the content with an onclick event handler using an ASP.
Pages:
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461