Microsoft.Web.UI.WebControls, MultiPage losing PageViews and ViewState contents

Posted on 2005-04-26
Last Modified: 2010-04-07
I am dynamically adding PageViews to a MultiPage control. With Debug I see the MultiPage PageView count increment to the correct number. When I do a Postback the MultiPage loses all the PageViews, the count going to 0.
The code is:
Dim objAppPage As New PageView

The mpGenApp is the MultiPage visible on the Web Form.

Thank you,
Question by:KentJackson777
    LVL 8

    Accepted Solution

    Whenever you dynamically generate a control, to my knowledge, they are lost on postback.  What you have to do is set the id of the dynamically generated control.  What I like to do is possibly store a control index in viewstate, and then append that to the id name when it is created.

    So if I had some textboxes.

    For i = 0 to numTextBoxes - 1
        Dim tb as new TextBox = "tb" & cStr(i)

    Then when you do a postback, just recreate the controls.  If the control has the same id as it had initially, it will retain all postback information.
    LVL 8

    Expert Comment

    LVL 12

    Assisted Solution

    You should move the code to create the dynamic control inside Page_Init,
    so it will get viewstate information on postback.
    and it should not be inside a
    if not ispostback then
    end if

    Author Comment

    Both marked responses gave me the solution. I needed to re-create the PageViews AND do it in Page_Init.
    Thank you both for your help

    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.

    This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
    A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
    It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
    Need more eyes on your posted question? Go ahead and follow the quick steps in this video to learn how to Request Attention to your question. *Log into your Experts Exchange account *Find the question you want to Request Attention for *Go to the e…

    759 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

    11 Experts available now in Live!

    Get 1:1 Help Now