User controls and disappearing values

Discussion in 'ASP .Net' started by =?Utf-8?B?Smlt?=, Nov 10, 2004.

  1. 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?
    =?Utf-8?B?Smlt?=, Nov 10, 2004
    #1
    1. Advertising

  2. Jim, behind what event are you loading the user control, and are you doing it
    on every postback?

    "Jim" wrote:

    > 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?
    >
    =?Utf-8?B?QmlsbCBCb3Jn?=, Nov 10, 2004
    #2
    1. Advertising

  3. 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.

    "Bill Borg" wrote:

    > Jim, behind what event are you loading the user control, and are you doing it
    > on every postback?
    >
    > "Jim" wrote:
    >
    > > 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?
    > >
    =?Utf-8?B?Smlt?=, Nov 10, 2004
    #3
  4. 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

    "Jim" wrote:

    > 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.
    >
    > "Bill Borg" wrote:
    >
    > > Jim, behind what event are you loading the user control, and are you doing it
    > > on every postback?
    > >
    > > "Jim" wrote:
    > >
    > > > 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?
    > > >
    =?Utf-8?B?QmlsbCBCb3Jn?=, Nov 10, 2004
    #4
  5. 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.

    "Bill Borg" wrote:

    > 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
    >
    > "Jim" wrote:
    >
    > > 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.
    > >
    > > "Bill Borg" wrote:
    > >
    > > > Jim, behind what event are you loading the user control, and are you doing it
    > > > on every postback?
    > > >
    > > > "Jim" wrote:
    > > >
    > > > > 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?
    > > > >
    =?Utf-8?B?Smlt?=, Nov 10, 2004
    #5
  6. 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

    "Jim" wrote:

    > 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.
    >
    > "Bill Borg" wrote:
    >
    > > 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
    > >
    > > "Jim" wrote:
    > >
    > > > 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.
    > > >
    > > > "Bill Borg" wrote:
    > > >
    > > > > Jim, behind what event are you loading the user control, and are you doing it
    > > > > on every postback?
    > > > >
    > > > > "Jim" wrote:
    > > > >
    > > > > > 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?
    > > > > >
    =?Utf-8?B?QmlsbCBCb3Jn?=, Nov 10, 2004
    #6
  7. 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.

    "Bill Borg" wrote:

    > 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
    >
    > "Jim" wrote:
    >
    > > 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.
    > >
    > > "Bill Borg" wrote:
    > >
    > > > 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
    > > >
    > > > "Jim" wrote:
    > > >
    > > > > 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.
    > > > >
    > > > > "Bill Borg" wrote:
    > > > >
    > > > > > Jim, behind what event are you loading the user control, and are you doing it
    > > > > > on every postback?
    > > > > >
    > > > > > "Jim" wrote:
    > > > > >
    > > > > > > 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?
    > > > > > >
    =?Utf-8?B?Smlt?=, Nov 11, 2004
    #7
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jerry Camel

    Disappearing Controls

    Jerry Camel, Feb 12, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    318
    Jerry Camel
    Feb 12, 2004
  2. =?Utf-8?B?QWxhbiBMYW1iZXJ0?=

    Values disappearing on PostBack

    =?Utf-8?B?QWxhbiBMYW1iZXJ0?=, Nov 3, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    577
    =?Utf-8?B?QWxhbiBMYW1iZXJ0?=
    Nov 4, 2004
  3. clintonG

    2.0 beta 2: Disappearing Controls

    clintonG, Sep 2, 2005, in forum: ASP .Net
    Replies:
    7
    Views:
    372
    JIMCO Software
    Sep 3, 2005
  4. =?Utf-8?B?anJicmFkeQ==?=

    TextBox Values Disappearing

    =?Utf-8?B?anJicmFkeQ==?=, Nov 15, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    361
    =?Utf-8?B?anJicmFkeQ==?=
    Nov 15, 2005
  5. Maciej Boniewicz

    Tomcat + TreeCache + disappearing values

    Maciej Boniewicz, Dec 1, 2005, in forum: Java
    Replies:
    2
    Views:
    644
    Maciej Boniewicz
    Dec 2, 2005
Loading...

Share This Page