LoadControl and PostBack Issue

C

Craig Buchanan

i am building a webform that dynamically loads one of two web usercontrols
during the webform's page_load event. during the postback i reload the
appropriate web usercontrol. so far so good.

unfortunately, none of the controls, except a label, have any values. what
am i not doing? all the controls on the WUC have enableviewstate set to
true.

thanks,

craig buchanan
 
C

Craig Buchanan

OK. I think I solved the problem.

I created a sub in the webform to dynamically load the controls based on a
ViewState value that I set in another event:

Sub LoadControls
Select Case ViewState("TabId")
Case TAB_GENERAL
Dim frmPersonGeneral1 As frmPersonGeneral =
LoadControl("frmPersonGeneral")
Me.Panel1.Controls.Add(frmPersonGeneral1)
Me.Panel1.Controls(0).Visible=True

'if this isn't a postback, get the data from the database or
whereever
If Not IsPostBack Then
frmPersonGeneral1.DataSource= 'set control's datasource
to sqldatareader or class
frmPersonGeneral1.DataBind
End If

Case TAB_PREFERENCE
...
End Select
End Sub

In the webform's form_load event, I set the ViewState variable and load the
controls the first time to be populated with data from the database:

Sub Page_Load
If Not IsPostBack Then
ViewState("TabId")= 'set to a querystring value
LoadControls()
End If
End Sub

Finally, in the webform's page_init event, I load the controls if there has
been a postback:

sub Page_Init
If IsPostBack Then LoadControls()
End Sub

I love to see if there is a way to improve this logic.

Thanks,

Craig
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top