Friday 29 July 2016

What is the significance of AutoEventWireUp in asp.net?



Gets or sets a value indicating whether events for ASP.NET pages are automatically connected to event-handling functions.

If AutoEventWireUp attribute is true then asp.net apges automatically connected to event-handling function, otherwise not.

The default value of AutoEventWireUp id true.

When AutoEventWireup is true, ASP.NET does not require that you explicitly bind event handlers to a page event such as Load.

When AutoEventWireup is false, you must explicitly bind the event to a method. For example, if you have a Page_Load method in the code for a page, the method will be called in response to the Load event only if you write code like that in the following example.

Example:-

Here AutoEventWireUp attribute value is false.

protected void Page_Load(object sender, EventArgs e)
    {
        Label1.Text = DateTime.Now.ToLongTimeString();
    }

For above example AutoEventWireup is false, so it will not show date on label control on web page.

Note:- 


  •   If you set AutoEventWireup to true, make sure that you do not also manually attach page event handlers to events. If you do, handlers might be called more than one time.

  • Automatic binding is performed only for page events, not for events for controls on the page.

  • As an alternative to binding events to handlers, you can override the Oneventname methods of the page or of controls.

No comments:

Post a Comment

Note: only a member of this blog may post a comment.