Even Page_PreRender is fired twice

Posted on 2006-06-08
Last Modified: 2012-06-21

I have aspx page on which I put user control A which derived from user control B.
When I moevd to Visual 2005 (ASP.NET 2.0), I noticed that Page_PreRender  in control B is fired twice.
When I put :
protected void Page_PreRender(object sender, System.EventArgs e)

in control A - the problem was solved (i.e. Page_PreRender of A is fired and Page_PreRender of B is fired only once).

But I want to understand why was it happpening?

P.S. I can't reconstruct this on simple project, created in Visual 2005. Maybe it's related to the fact that the project was migrated from Visual 2003, or there is somethign else different in my project that causes to such strange behavior?
Question by:netformx
    LVL 5

    Expert Comment


    i think you should rewrite your application in VS2005 from scratch... maybe opening it and converting it to newer version may cause some problems..
    thats what happened to me when i used to do that between earlier versions in

    LVL 1

    Expert Comment

    It sounds like whats happened is your B control automatically calls its prerender event and your A control generated code called control B's again. When you wrote protected void Page_PreRender(object sender, System.EventArgs e) {} you override the generated statement thus removing the duplicate call. If you where to write

    protected void Page_PreRender(object sender, System.EventArgs e)
                this.Page_PreRender(sender, e); 'Call the original statement

    it should reproduce the problem. If it doesn't reproduce then post again and hopefully we can find out exactly whats happening.

    Hope this helps.

    Author Comment


     "your B control automatically calls its prerender event and your A control generated code called control B's again. " - why it worked OK in Visuall 2003? Why this behavior is not reproducable on simple project created in Visual2005 (when control A does not have its protected void Page_PreRender) , what's special in my project? Is this known issue? it happened to you too?
    LVL 1

    Accepted Solution

    I believe this happened becuase unneeded code was generated when it was converted. so writing a new project in vs2005 wouldn't reproduce the error becuase it did not generate the code. It would have worked fine in vs2003 becuase no "excess" code was writen/generated when you first designed the project.  In VS2005 a lot of code is "hidden" from the user. So unless you put the Page_PreRender in your code, the generated code (that you cannot see) will run. I have had nothing but problems converting projects, I have found it much faster and cleaner just to rewrite my projects. Just my opinion. Hope this helps.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    6 Surprising Benefits of Threat Intelligence

    All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

    In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
    In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
    Sending a Secure fax is easy with eFax Corporate ( First, Just open a new email message.  In the To field, type your recipient's fax number You can even send a secure international fax — just include t…
    This video discusses moving either the default database or any database to a new volume.

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    10 Experts available now in Live!

    Get 1:1 Help Now