why controls keep their state even on a different page?

Ask a Question related to ASP.NET General, Design and Development.

  1. #1

    Default why controls keep their state even on a different page?

    I have
    1. A main form with 2 buttons (btn1 and btn2) and a place holder (ph)
    2. A Web User Control (ctl1) containing a textbox (txt)
    3. A Web User Control (ctl2) containing a textbox (txt)

    When I press btn1 I have the following code:
    ph.Controls.Add(LoadControl("ctl1.ascx"))

    When I press btn2 I have the following code:
    ph.Controls.Add(LoadControl("ctl2.ascx"))

    In ctl1 I have the following line on form load:
    txt.Enabled = False


    When I press btn1 ctl1 is loaded and the txt is disabled. When I press btn2
    ctl2 is loaded and the txt is disabled. Why the txt on ctl2 is disabled? and
    how can I avoid it? Somehow it remembered the state of the textbox from the
    previous loaded page. Why?


    Bisser Milanov Guest

  2. Similar Questions and Discussions

    1. Maintaining state in programmatically created composite user controls
      Hi I'm writing a timesheet application in ASP.NET (framework 1.1, VS 2003) that includes a user control to manage project time allocation...
    2. Losing Postback state with composite controls
      Not sure how to go about explaining this, which is never a good sign. I have a Custom UserControl I've built, which contains 1 drop-down list and...
    3. Maintaining View State For Dynamically Created Controls
      I am building a custom control that I want to server as a container for child controls that can be dynamically added to this control. I can persist...
    4. Preserving state of radio controls
      Hi. One custom control I am creating generates a series of radio buttons. These are html radio buttons, not the server version. When I run the...
    5. persist state of controls in a custom control
      Specify the control to implement INamingContainer interface. Also properties that need to be preserved, example is the GroupName property, would...
  3. #2

    Default Re: why controls keep their state even on a different page?

    Viewstate is based on a control's position in the hierarchical control tree
    and you are loading different controls into the same position each time.
    You either need to setup different placeholders so that each set of controls
    is loaded into a different placeholder, or manually deal with consequences.

    Thanks, Paul Wilson (MVP)


    Paul Wilson [MVP] Guest

  4. #3

    Default Re: why controls keep their state even on a different page?

    Hm, what is the purpose of a Place Holder then? If I will load always the
    same control in this placeholder I will simply put the control itself on the
    page. Why would I put it into a placeholder?
    I actually tried to clear the viewstate when I load different control but it
    didn't work. I tried to clear the view state of the control of the main form
    of the text box itself but nothing worked. Any ideas how to clear the view
    state?


    Bisser Milanov Guest

  5. #4

    Default Re: why controls keep their state even on a different page?

    forget the 'position' stuff give the conflicting controls different names
    that has solved this problem for us.


    "Bisser Milanov" <bm@bm.bm> wrote in message
    news:uph2gyjSDHA.2228@tk2msftngp13.phx.gbl...
    > Hm, what is the purpose of a Place Holder then? If I will load always the
    > same control in this placeholder I will simply put the control itself on
    the
    > page. Why would I put it into a placeholder?
    > I actually tried to clear the viewstate when I load different control but
    it
    > didn't work. I tried to clear the view state of the control of the main
    form
    > of the text box itself but nothing worked. Any ideas how to clear the view
    > state?
    >
    >

    gerry Guest

  6. #5

    Default Re: why controls keep their state even on a different page?

    If you have a different placeholder for each possible user control you
    may load then the relative positions will be unique. By the way, unique
    control ways does not work with viewstate, although it will work if your
    problem is just the posted values.

    Thanks, Paul Wilson (MVP)


    *** Sent via Developersdex [url]http://www.developersdex.com[/url] ***
    Don't just participate in USENET...get rewarded for it!
    Paul Wilson Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139