The Click Web Form Code-Behind Class File
using System;
using System.Collections.Generic;
using System.Web.UI;
namespace ControlsBook2Web.Ch08
{
public partial class Click : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
BottomLabel.Attributes.Add("onclick",
"alert('BottomLabel clicked!');");
}
}
}
352 CHAPTER 8 ?– I NTEGRAT ING CLI ENT-SI D E SCRIPT
Controls such as Button, LinkButton, and ImageButton have additional support for click
handling that goes beyond the preceding sample. The OnClientClick attribute can be set on
these controls in either the .aspx page or in the code-behind class as a property to achieve the
same effect that we showed with the Label controls.
Now that we have introduced how to add client-side script to a server control, we move on
to a more interesting example of providing image rollovers within a server control by integrating
client-side scripts.
Handling Mouse Events for Image Rollovers
Although the ASP.NET Image control makes it easy to assign image URL information through its
Designer property support, its distinct lack of rich functionality provides ample room for
improvement. A nice extension to this control would be the capability to perform client-side
image mouse rollovers.
Pages:
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465