By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,846 Members | 1,631 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,846 IT Pros & Developers. It's quick & easy.

nested dropdownlist loses values - only in one instance

P: n/a
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
Nov 18 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
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!
Nov 18 '05 #2

P: n/a
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 <na***@dao2com.com> wrote in message news:<#F*************@TK2MSFTNGP10.phx.gbl>...
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!

Nov 18 '05 #3

P: n/a
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 <na***@dao2com.com> wrote in message news:<#F*************@TK2MSFTNGP10.phx.gbl>...
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!

Nov 18 '05 #4

P: n/a
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 <na***@dao2com.com> wrote in message news:<#F*************@TK2MSFTNGP10.phx.gbl>...
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!

Nov 18 '05 #5

P: n/a
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?

ba*@kleinbuendel.com (Bryan Ax) wrote in message news:<7a**************************@posting.google. com>...
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

Nov 18 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.