textboxes in dynamically loaded WUC not repopulated during PostBack

C

Craig Buchanan

i am building a webform that dynamically loads one of two web usercontrols
during the webform's page_load event. i am using label, named TabId, on the
webform to persist which WUC should be loaded. during the postback i reload
the appropriate web usercontrol based on the value in TabId. so far so
good.

unfortunately, when i postback this WUC, none of the controls in the WUC,
except labels, have any values. what am i not doing? all the controls on
the WUC have enableviewstate set to true. i've read that i should move the
loadcontrol to the page_init event, but then the value for TabId is blank.

I would really appreciate some guidance. 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

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top