nested dropdownlist loses values - only in one instance

Discussion in 'ASP .Net' started by Bryan Ax, Jun 2, 2004.

  1. Bryan Ax

    Bryan Ax Guest

    I have a page that has two copies of the same control in it. The
    control is:

    BorrowerControl

    the two references to it in the page are

    bControl1
    cobControl1

    The control contains a dropdownlist that is populated from xml. I only
    bind this data on page_load, not on subsequent postbacks (shouldn't
    need to). Code to bind (where this.States is a dataset on the page)
    is:

    foreach(DataRow d in this.States.Tables[0].Rows)
    {
    string txt = d["abv"].ToString();
    string val = d["abv"].ToString();
    li = new ListItem(txt, val);
    control.Items.Add(li);
    }
    control.DataBind();

    I'm getting some REALLY strange behavior. The dropdownlist in
    bControl1 maintains its values on postback, but the dropdownlist in
    cobControl1 does not. I haven't found anything that says I can't have
    multiple copies of the same control on the page, or that would explain
    this type of erratic behavior. Can someone shed some light on this
    situation? I can provide more detail if necessary. And no, I don't
    have enableViewState = false on either instance of the control.

    Sincerely,

    Bryan Ax
    Bryan Ax, Jun 2, 2004
    #1
    1. Advertising

  2. Bryan Ax

    Natty Gur Guest

    Hi,

    Is that custom server control? if so, did you implement IStateManager,
    and how.

    by the way why you are using DataBind. you add explicitly items to items
    collection. you don't bind your control to any datasource.

    Natty Gur[MVP]

    blog : http://weblogs.asp.net/ngur
    Mobile: +972-(0)58-888377


    *** Sent via Developersdex http://www.developersdex.com ***
    Don't just participate in USENET...get rewarded for it!
    Natty Gur, Jun 2, 2004
    #2
    1. Advertising

  3. Bryan Ax

    Bryan Ax Guest

    It's a user control (.ascx), not a custom server control. It does use
    a custom implementation of viewstate, saving to a database. However,
    that doesn't explain to me why one instance of it would work ok, and
    the other not.

    Databind was commented out from an earlier attempt. Forgot to include
    that.

    Bryan

    Natty Gur <> wrote in message news:<#>...
    > Hi,
    >
    > Is that custom server control? if so, did you implement IStateManager,
    > and how.
    >
    > by the way why you are using DataBind. you add explicitly items to items
    > collection. you don't bind your control to any datasource.
    >
    > Natty Gur[MVP]
    >
    > blog : http://weblogs.asp.net/ngur
    > Mobile: +972-(0)58-888377
    >
    >
    > *** Sent via Developersdex http://www.developersdex.com ***
    > Don't just participate in USENET...get rewarded for it!
    Bryan Ax, Jun 2, 2004
    #3
  4. Bryan Ax

    Bryan Ax Guest

    More info....

    I removed the custom viewstate implementation, just went back to
    having the page extend from System.Web.UI.Page. Still didn't work. Now
    the page stores viewstate just like any other, and it is still not
    functional.



    Natty Gur <> wrote in message news:<#>...
    > Hi,
    >
    > Is that custom server control? if so, did you implement IStateManager,
    > and how.
    >
    > by the way why you are using DataBind. you add explicitly items to items
    > collection. you don't bind your control to any datasource.
    >
    > Natty Gur[MVP]
    >
    > blog : http://weblogs.asp.net/ngur
    > Mobile: +972-(0)58-888377
    >
    >
    > *** Sent via Developersdex http://www.developersdex.com ***
    > Don't just participate in USENET...get rewarded for it!
    Bryan Ax, Jun 2, 2004
    #4
  5. Bryan Ax

    Bryan Ax Guest

    OK, I think I've identified where the problem happens, but I don't
    understand the why. Hopefully, someone can fill me in.

    The following code fails. All I'm trying to do is populate two
    dropdownlists from the same set of items (in my real case, a list of
    states, but this is just a test).

    When I execute the following, the first one fills just fine, but the
    second one does not, i.e. the line this.loadDdl(this.DropDownList2)
    does not populate the dropdownlist with items. Can someone please
    explain to me why it doesn't work? I'm really missing something that
    must be obvious.


    private void loadDdl(DropDownList control)
    {
    ListItem li = new ListItem("Hello", "world");
    control.Items.Add(li);
    li = new ListItem("Goo", "ber");
    control.Items.Add(li);
    li = new ListItem("gee", "whiz");
    control.Items.Add(li);
    }

    private void Page_Load(object sender, System.EventArgs e)
    {
    // Put user code to initialize the page here
    if (! this.Page.IsPostBack)
    {
    this.loadDdl(this.DropDownList1);
    this.loadDdl(this.DropDownList2);
    }
    }


    Natty Gur <> wrote in message news:<#>...
    > Hi,
    >
    > Is that custom server control? if so, did you implement IStateManager,
    > and how.
    >
    > by the way why you are using DataBind. you add explicitly items to items
    > collection. you don't bind your control to any datasource.
    >
    > Natty Gur[MVP]
    >
    > blog : http://weblogs.asp.net/ngur
    > Mobile: +972-(0)58-888377
    >
    >
    > *** Sent via Developersdex http://www.developersdex.com ***
    > Don't just participate in USENET...get rewarded for it!
    Bryan Ax, Jun 2, 2004
    #5
  6. Bryan Ax

    Bryan Ax Guest

    Actually, my last post was incorrect. That did work OK - just hadn't
    recompiled.

    However, this time I have figured it out. On the user control that's
    problematic, I'm removing a validation control, i.e.

    this.Controls.Remove(this.ValidationControl);

    during the page_load event.

    That line of code causes the problem. No clue as to why removing one
    control would affect others on the page, and ONLY dropdownlists on the
    page (other controls like textboxes are not affected). The validation
    control does not apply to the dropdownlist at all.

    I tried moving that line to prerender, still broke it. I've gotten
    around it by just setting the enabled of it to false, but it still
    doesn't explain the why to me.

    Anyone?

    (Bryan Ax) wrote in message news:<>...
    > I have a page that has two copies of the same control in it. The
    > control is:
    >
    > BorrowerControl
    >
    > the two references to it in the page are
    >
    > bControl1
    > cobControl1
    >
    > The control contains a dropdownlist that is populated from xml. I only
    > bind this data on page_load, not on subsequent postbacks (shouldn't
    > need to). Code to bind (where this.States is a dataset on the page)
    > is:
    >
    > foreach(DataRow d in this.States.Tables[0].Rows)
    > {
    > string txt = d["abv"].ToString();
    > string val = d["abv"].ToString();
    > li = new ListItem(txt, val);
    > control.Items.Add(li);
    > }
    > control.DataBind();
    >
    > I'm getting some REALLY strange behavior. The dropdownlist in
    > bControl1 maintains its values on postback, but the dropdownlist in
    > cobControl1 does not. I haven't found anything that says I can't have
    > multiple copies of the same control on the page, or that would explain
    > this type of erratic behavior. Can someone shed some light on this
    > situation? I can provide more detail if necessary. And no, I don't
    > have enableViewState = false on either instance of the control.
    >
    > Sincerely,
    >
    > Bryan Ax
    Bryan Ax, Jun 2, 2004
    #6
    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. Cowboy \(Gregory A. Beamer\)

    Re: Server.Transfer loses posted values only v1.1

    Cowboy \(Gregory A. Beamer\), Jul 24, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    436
    Cowboy \(Gregory A. Beamer\)
    Jul 24, 2003
  2. =?Utf-8?B?am1hdHZpYWs=?=

    Dynamic DropDownList loses index

    =?Utf-8?B?am1hdHZpYWs=?=, Nov 10, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    375
    =?Utf-8?B?am1hdHZpYWs=?=
    Nov 10, 2005
  3. Al in Dallas
    Replies:
    2
    Views:
    283
    Al in Dallas
    Aug 1, 2006
  4. Replies:
    6
    Views:
    266
    Bruno Desthuilliers
    Jul 10, 2007
  5. Graham Stevenson

    Dropdownlist in Server Control loses Viewstate

    Graham Stevenson, Dec 1, 2003, in forum: ASP .Net Building Controls
    Replies:
    2
    Views:
    134
    Guest
    Dec 3, 2003
Loading...

Share This Page