locked
Custom User Control Running Multiple Times RRS feed

  • Question

  • User680026537 posted

    Hello,

    I have a strange problem that I ran across testing something else on my site.  On my Default.aspx page, I register a user control and call it to render and fill in some HTML on the page.

    <%@ Register Src="controls/Home/GetFriendFeed.ascx" TagName="GetFriendFeed" TagPrefix="uc1" %>

    <uc1:GetFriendFeed ID="GetFriendFeed1" runat="server" />

    When I go to Default.aspx, it calls the control once, not a problem.  I have a nested MasterPage (not sure if that is the cause), that is the same for both of these pages.  When I go to another page, profile.aspx, that does NOT have the @Register or the user control anywhere on the page, the user control executes 3 times. 

    I'm not sure what the cause of this is.  Any help or advice of where to look would be helpful!

     

    Thank you

    Sunday, April 10, 2011 6:25 PM

All replies

  • User-610330605 posted

    You have mentioned that the control is not registered in the second page.

    Is the control registered in Web.config or Master page?

    Is the control added in the page in the ASPX or dynamically in code behind?

    Tuesday, April 12, 2011 10:37 AM
  • User680026537 posted

    Hi Jerry,


    I only have the reference to the user control on Default.aspx and use it on Default.aspx.  I don't have the @Register on any other page, specifically the masterpages, where I first thought the problem might be, and I don't have it in the web.config file. 

    I'm not sure how long it has been like this, but I just noticed it after I introduced nesting masterpages on this page.

    Any ideas? 

    Wednesday, April 13, 2011 5:46 PM
  • User1957418580 posted

    Can you give us an idea of your directory structure and how your master pages are nested?  Also, how do you determine that the control runs 3 times?  Have you set breakpoints in it?

    Monday, April 18, 2011 6:30 AM
  • User680026537 posted

    The masterpages and Default.aspx are in the root directory.  I found it by accident by using break points.  Earlier I was working on the user control, so I had break points in there and I noticed that when I went to other pages that are in the root directory, that also use the masterpages, the user control was going through the break points - but it shouldn't have - because the user control is only used on Default.aspx.

    Monday, April 18, 2011 7:18 AM
  • User1957418580 posted

    Nothing in the global.asax that might do some kind of redirect to the default page?  Maybe some URL Routing that could be involving the Default.aspx?  This might be tough to speculate on over forums.  Curious, if you make a test page that does the exact same thing as the default page (call it test.aspx), and another page that does nothing but maybe "Hello World" (call it dummy.aspx) - each using no master page, does the problem occur?  If not, add in the master page to the test.aspx and see if it happens, and then the dummy page and see if that triggers it.  There must be just something unusual here that we're missing - it certainly should not behave as you describe.

    Monday, April 18, 2011 9:55 AM
  • User680026537 posted

    That's a good test to run.  I will go ahead and try to test and see other triggers I can find and hopefully figure out the problem or at least be able to come back with more information.  I can imagine this is my fault - I just cannot determine what it is! hah...I appreciate your help.

    Monday, April 18, 2011 10:02 AM
  • User-16411453 posted

    Pages only load once in the page life cycle.

    If you add a dropdownlist, and code in on selected index changed, and then change the value of the dopdownlist on page load, then the page will load twice.

    You just fired an postback event on the intial page load, thus loading the page twice.

    So you have to further define the event handler, such as if Page.IsPostback then, to isolate events to occur after the page init and load events.

    So it sounds like your control handles the page cycle, and the other stuff does not.

     

    Friday, April 22, 2011 10:59 PM
  • User680026537 posted

    Stepping through my code, I see that things go pretty well at first...I have 2 masterpages MasterPage.master and profile.master.

    MasterPage.master goes through the init and then profile.master will...the load functions for both and the load function for my aspx page, however, all of a sudden the MasterPage.master starts over at init and then goes through the Default.aspx page - a page I'm not even on!  The Default.aspx page is the page that calls the control.  When I'm on the Default page that's fine, but I don't want this code or the control to be called when I'm on another page.

    It seems like as the page is already loaded and maybe going through the unload event, it starts all over, calling the MasterPage and Default page.

    I haven't found out too much more than that at this point.  I'll write back when I find out more.

    Thursday, May 19, 2011 6:49 AM
  • User-16411453 posted

    huh?

    That's like finding a nail in the haystack. Best thing to do is tear apart the program, copy it into a temp text file, and reconstruct the program one module at a time, until it runs twice again.

    Tuesday, June 7, 2011 12:53 AM