ASP.NET Web Control Client-Side Event Demo

This demo illustrates how the use the Attributes collection to add client-side code to an ASP.NET Web control's client-side event. Below you will see a button: move the mouse over the button and a messagebox should appear (assuming your browser supports client-side JavaScript code). The HTML rendered by the Button control is as follows:
<input type="submit" name="btnClick" value="Click Me!" id="btnClick" onmouseover="alert('Hello, World!');" />



Source Code

<script language="vb" runat="server">

  Sub Page_Load(sender As Object, e As EventArgs)

    'Set the button's client-side onmouseover event

    btnClick.Attributes("onmouseover") = "alert('Hello, World!');"

  End Sub

</script>



<form runat="server">

  <asp:button runat="server" Text="Click Me!" id="btnClick" />

</form>


[Return to the article]