ASP. NET getting started Tutorial: Event handle, asp.net getting started tutorial

Source: Internet
Author: User

ASP. NET getting started Tutorial: Event handle, asp.net getting started tutorial

Event handler is a subroutine used to execute code for a given event.

ASP. NET-event handle

See the following code:

<%lbl1.Text="The date and time is " & now()%>

When will the above Code be executed? The answer is: "I don't know..." this article is for webpage teaching www.webjx.com to collect and organize or original content. For reprinting, please indicate the source!

Page_Load event

Page_Load is one of the many events that ASP. NET can understand. The Page_Load event is triggered when the page is loaded. ASP. NET automatically calls the child routine Page_Load and runs the Code:

<script runat="server">Sub Page_Loadlbl1.Text="The date and time is " & now()End Sub</script>

Note: This Page_Load event does not contain object references or event parameters!

Page. IsPostBack attributes

The Page_Load subroutine runs each time the page is loaded. If you only want to execute code in the Page_Load subroutine when the Page is loaded for the first time, you can use the Page. IsPostBack attribute. If the Page. IsPostBack attribute is false, the Page is loaded for the first time. If it is true, the Page is returned to the server (for example, by clicking the 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 preceding example only creates The message "The date and time is..." When The page is loaded for The first time. When you click the Submit button, the submit subroutine creates "Hello World!" in the second label! ", But the date and time in the first label will not change.

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

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.