Create a page instance variable

Posted on 2009-04-29
Last Modified: 2012-05-06
I'm trying to create and manipulate a page variable.

e.g. I have a page called Default:

Default myPage = new Default();

this compiles and runs ok, but all the controls within the myPage variable are null, I want to instantiate the page fully.
I've tried calling RenderControl on it but it hasn't made any difference and I just get an empty string as the output.

Any ideas how I could go about this?
Question by:NazoUK
    LVL 10

    Expert Comment

    Where does your page variables are set?  If they are not set in the constructor, its normal that they are Null.   Why do you want to instantiate a page without showing it exactly?

    P.S: Any code would be appreciated

    LVL 6

    Expert Comment

    Are you creating the page manually at runtime, or are you using the Visual Studio design surface?

    If you're doing it manually, then you have to do all the grunt work manually as far as declaring the controls and their positions, attributes and values. That's why the design surface is so handy when creating pages. All that work is done for you behind-the-scenes.

    LVL 15

    Author Comment

    The page in question has some Web Parts and a Web Part manager.
    What I'm trying to do is to create an instance of that page inside a web service, and then use the Web Part manager on the page to move the web parts around.

    When I step through in the debugger and examine the myPage variable I can see the Web Part Manager and other controls in there, but they are all null.

    I'm just experimenting at the moment and this is probably a  dead end anyway but I thought I'd see if anyone had done anything similar.
    LVL 15

    Accepted Solution

    Not such a dead-end after all: I found a blog post that shows how to do it, for the same scenario I'm trying to do:

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
    User art_snob ( encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
    Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
    This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor ( If you're looking for how to monitor bandwidth using netflow or packet s…

    730 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

    18 Experts available now in Live!

    Get 1:1 Help Now