Asp. NET Getting Started Tutorial: event handlers

Source: Internet
Author: User

Event handler is a subroutine that executes code for a given event.

ASP. NET-Event handle

Take a look at the following code:

<%lbl1. Text= "The date and Time is" & Now ()%>

When will the above code be executed? The answer is: "I do not know ..." This is the Web page teaching www.webjx.com collection or original content, reproduced please indicate the source!

Page_Load events

The Page_Load event is one of the many events that are understood by ASP. The Page_Load event is triggered when the page loads, and ASP. NET automatically calls the subroutine Page_Load and executes the code in it:

<script runat= "Server" >sub page_loadlbl1.text= "The date and Time is" & Now () End sub</script>

Note: The Page_Load event does not contain object references or event arguments!

Page.IsPostBack Property

The Page_Load subroutine runs every time the page loads. You can use the Page.IsPostBack property if you only want code in the Page_Load subroutine to be executed the first time the page is loaded. If the Page.IsPostBack property is False, the page is loaded for the first time, and if true, the page is passed back to the server (for example, by clicking a button on the form):

<script runat= "Server" >sub page_loadif not Page.IsPostBack then  lbl1. Text= "The date and Time is" & Now () End IfEnd SubSub Submit (s as Object, E as EventArgs) lbl2. text= "Hello world!" End sub</script>

The above example creates "the date and time is ..." only when the page is first loaded. The message. When the user clicks the Submit button, the Submit subroutine creates a "Hello world!" in the second label, but the date and time in the first label do not change.

Reprinted from: http://www.aspnetjia.com/Cont-1145.html

Asp. NET Getting Started Tutorial: event handlers

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.