Even Page_PreRender is fired twice

Hi,

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?
netformxAsked:
Who is Participating?
 
matt3ewCommented:
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.
0
 
t_itaniumCommented:
hi

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 VS.net

cheers
0
 
matt3ewCommented:
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.
0
 
netformxAuthor Commented:

 "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?
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.