User controls and disappearing values

G

Guest

I have a user control that I am dynamically loading into an aspx page. When
I fill out the text boxes and submit the form using a command button on the
aspx page I lose the value from the user control. I have an Error-checking
function in the user control that I invoke from the aspx page. This method
fires and detects an error even though I fill the the text box with text.
Now, if I fill out the text box again with text everything goes smooth
sailing and I am able to continue. I am loading the user control using the
following methodology:

tenant_setup.scheduling.userbehaveproblems userBehaveProblem = new
tenant_setup.scheduling.userbehaveproblems();//form level variable declaration


userBehaveProblem = LoadControl ("userbehaveproblems.ascx") as
tenant_setup.scheduling.userbehaveproblems;//gets an instance of the control

pnlUserControl.Controls.Add (userBehaveProblem);//loads the control in the
panel


userBehaveProblem.HasErrors ();//the method call

I think it is a state problem, and I have the view state enabled. Any
suggestions?
 
G

Guest

I am loading the controls off of a combo box post back, but I am not
reloading the user control after the command button click event is fired. I
assumed since I declare the user controls as being form level I would not
have to.
 
G

Guest

If the control and its textbox are not there after postback, there's no place
for the text you just entered to return to. Try loading the control each
time. Curious, in this case, how are you invoking the error-checking function
after postback if that control doesn't exist?

Bill
 
G

Guest

I think you may have misunderstood. The user control is there, just not the
value that I typed into the text box of the user control.
 
G

Guest

If I'm understanding you right, you are doing the loadcontrol in the
selectionchanged event of the combo box (autopostback=true), e.g.

panel1.Controls.Add(LoadControl("test.ascx"))

Is that right? If so, that control only *looks* like it's there (you see it
on the screen), but it's not *really* there after the next postback (e.g. the
button click), because everything starts from scratch again on the page load.

Not sure if you have a wide variety of user controls you're adding, but if
the number is small you might consider putting them *all* on the panel at
design-time, then let your combobox set visible on/off for the ones you want.

Let me know if this helps or if I'm still missing something.

Bill
 
G

Guest

Yah, I have approximately 40 different controls that I need to be able to
load, so I will just come up with something in the command button click
event. Thanks for all of your help, however.
 

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,744
Messages
2,569,482
Members
44,900
Latest member
Nell636132

Latest Threads

Top