Viewstate and user control

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Hardy Wang

    Viewstate and user control

    Hi all,
    I have a main ASPX page, and a control ASCX page, there is a Repeater
    control in ASCX page, and several drop down boxes in main page. These drop
    down boxes will trigger postback.
    In the ASCX page, if I put code like
    private void Page_Load(objec t sender, System.EventArg s e) {
    if (! Page.IsPostBack ) {
    Data_Binding(); // to populate values in Repeater
    }
    }
    Everytime when the page posts back because of drop down box selection
    change, I loose all content in the Repeater. I enabled ViewState in ASCX and
    Repeater control. If I let page to run Data_Binding() regardless of postback
    status, then it is fine.
    In my mind, Viewstate should remember what is for Repeater, I should not
    need to commnet out the line if (! Page.IsPostBack ) to make page to recreate
    the Repeater everytime.

    Any idea?

    Thanks!

    --
    WWW: http://hardywang.1accesshost.com
    ICQ: 3359839
    yours Hardy


  • cbDevelopment

    #2
    Re: Viewstate and user control

    The only time I have seen this behavior is when the main page is loading
    the control dynamically using LoadControl().

    "Hardy Wang" <hardywang@hotm ail.com> wrote in
    news:u7cDUg4yFH A.2960@tk2msftn gp13.phx.gbl:
    [color=blue]
    > Hi all,
    > I have a main ASPX page, and a control ASCX page, there is a
    > Repeater
    > control in ASCX page, and several drop down boxes in main page. These
    > drop down boxes will trigger postback.
    > In the ASCX page, if I put code like
    > private void Page_Load(objec t sender, System.EventArg s e) {
    > if (! Page.IsPostBack ) {
    > Data_Binding(); // to populate values in Repeater
    > }
    > }
    > Everytime when the page posts back because of drop down box
    > selection
    > change, I loose all content in the Repeater. I enabled ViewState in
    > ASCX and Repeater control. If I let page to run Data_Binding()
    > regardless of postback status, then it is fine.
    > In my mind, Viewstate should remember what is for Repeater, I
    > should not
    > need to commnet out the line if (! Page.IsPostBack ) to make page to
    > recreate the Repeater everytime.
    >
    > Any idea?
    >
    > Thanks!
    >[/color]

    Comment

    Working...