• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 409
  • Last Modified:

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

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
Me.mpGenApp.Controls.Add(objAppPage)

The mpGenApp is the MultiPage visible on the Web Form.

Thank you,
Kent
0
KentJackson777
Asked:
KentJackson777
  • 2
2 Solutions
 
thrill_houseCommented:
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.id = "tb" & cStr(i)
Next

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.
0
 
thrill_houseCommented:
0
 
laotzi2000Commented:
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
block.
0
 
KentJackson777Author Commented:
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
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now