ASP.NET Event Handler
An Event Handler is to execute code for a given event. The Page_Load event
is triggered when a page loads. For example:
<script runat="server">
Sub Page_Load
lbl1.Text="Free online courses from iTechCollege.com"
End Sub
</script>
<html>
<body>
<form runat="server">
<p><asp:label id="lbl1" runat="server" /></p>
</form>
</body>
</html>
In the above example, the Page_Load subroutine runs every time when the page
is loaded. If you want the Page_Load subroutine is only executed at the first
time the page is loaded, you can use the Page.IsPostBack property. If the Page.IsPostBack
property is false, the page is loaded for the first time, if it is true, the
page is posted back to the server. See the following example:
<script runat="server">
Sub Page_Load
if Not Page.IsPostBack then
lbl1.Text="Best GPS Store - www.SelectaGPS.com"
end if
End Sub
Sub submit(s As Object, e As EventArgs)
lbl2.Text="Buy wireless devices from iShopSale.com"
End Sub
</script>
<html>
<body>
<form runat="server">
<p><asp:label id="lbl1" runat="server" /></p>
<p><asp:label id="lbl2" runat="server" /></p>
<asp:button text="Submit" onclick="submit" runat="server"
/>
</form>
</body>
</html>
As you can see, the example above will write the "Buy wireless devices
from iShopSale.com" message only the first time the page is loaded. When
a user clicks on the Submit button, the submit subroutine will write "Best
GPS Store - www.SelectaGPS.com".
|