locked
My webpart class constructor runs twice? RRS feed

  • Question

  • Hi,

    I have been developing a webpart in VS 2008. I created some methods, ran the code and it worked reasonably well. Just recently though while still developing the webpart it has stopped doing what it's supposed to. (A popup needs to appear on the screen).

    I attached the w3wp process to the debugger and stepped through the code. I noticed that once it had run through the methods I specified in my constructor it then went on to run the whole thing again (the yellow step marker moved back to the top of the class constructor).

    After it's run the methods for the second time it then goes on to run the override Render method except now because a variable has changed during the second run it doesn't print out the code for my popup.

    When I first created the project I accidentally gave the class name a lowercase first letter, so it reads 'annPopup'. Might this be the cause?

    If not does anyone have any other ideas?

     

    Monday, April 26, 2010 12:14 PM

Answers

  • Hi there.

    You have most likely got two web parts assigned to the page. Add this query parameter to your URL: "?contents=1" to enter the Web Part Maintenance page. For example, http://myserver/default.aspx?contents=1

    In this page, look to see if you have your web part show up twice. You probably have a duplicate that says "Open on Page?" = no.

    Put a check mark on that one and click Delete.

    Hope this helps.

    Regards,

    Magnus


    My blog: InsomniacGeek.com
    • Marked as answer by nab89 Monday, April 26, 2010 1:10 PM
    Monday, April 26, 2010 12:56 PM

All replies

  • Hi there.

    You have most likely got two web parts assigned to the page. Add this query parameter to your URL: "?contents=1" to enter the Web Part Maintenance page. For example, http://myserver/default.aspx?contents=1

    In this page, look to see if you have your web part show up twice. You probably have a duplicate that says "Open on Page?" = no.

    Put a check mark on that one and click Delete.

    Hope this helps.

    Regards,

    Magnus


    My blog: InsomniacGeek.com
    • Marked as answer by nab89 Monday, April 26, 2010 1:10 PM
    Monday, April 26, 2010 12:56 PM
  • Yup that was it. I had two on that page, one of which was hidden.
    Deleted one, opened the page and it works fine now! Thanks for the tip Magnus.

    Monday, April 26, 2010 1:10 PM
  • Sorry to bring this up again but I am having the same problem. I have checked the Web Part Maintenance page and there is definitely only one instance of my web part there.

    My code on one refresh of the page ran 4 times. Funnily enough this only seems to happen when the web part is added to the root site default.aspx page, anywhere else it runs only once through the code.

    What my webpart is doing is reading/creating a http cookie checking user is a member of an AD group, reading some files, retrieving some list data, and then printing out this information by overriding the Render method where I also Render a control (button) using RenderChildren().

    Is there anything here that could be causing this problem?

    Also, not sure if this is related but I'm finding that the cookie I'm creating isn't being found the next time the webpart is run - it returns null when looking for it.

    Wednesday, June 2, 2010 10:39 AM