Title

Kodyaz Development Resources

Development resources, articles, tutorials, samples, codes and tools for .Net, SQL Server, Vista, etc.
Welcome to Kodyaz Development Resources Sign in | Join | Help
in Search

Eralper's Blog on Software Development



ASP.NET pages load twice and passes the Page.IsPostBack control statement

Hello,


I had a problem with loading an ASP.NET page twice recently. I knew from my previous experiences with such a problem that one of the main reasons that cause loading an ASP.NET page twice is the AutoEventWireup attribute of the page declaration in ASP.NET pages.

If AutoEventWireup attribute is set to True and if you are using an IDE like MS Visual Studio in your development environment, since Visual Studio automatically binds events to controls and because of AutoEventWireup attribute is True identifiying page events to be wired up automatically, each event triggered is processed twice on the server side.

But there is one reason causing events defined to be triggered twice on the server side. I think this happens when you copy and go editing on an existing asp.net web page on the Microsoft Visual Studio 2005 or VS2008 rapid development IDE environments.

Here is the reason I'm trying to mention above.

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load, Me.Load

You see Page_Load event is defined twice for MyBase.Load and Me.Load (Page.Load) events. So it runs twice and even if you try to control the flow of the process using Page.IsPostBack property you will fail to prevent the execution of the Page_Load sub routine twice.

Removing the MyBase.Load will work successfully in this case.

Published Saturday, July 05, 2008 4:52 PM by eralper
Filed Under: ,

Comments

No Comments
Anonymous comments are disabled
Copyright © 2004 - 2008 Eralper Yilmaz. All rights reserved.
Powered by Community Server, by Telligent Systems