ASCX User Control Drop Down List Issues

R

runtoofar

I have an ASCX user control with a drop down list inside an ASPX (C#)
page. The user selects an item from the DDL, clicks a button, and the
DDL.SelectedValue is supposed to be sent to another function. However,
the SelectedValue is always the first value in the DDL. I have tried
several methods to work around this including the examples at:

http://www.mastercsharp.com/article.aspx?ArticleID=67&&TopicID=2
http://odetocode.com/Articles/116.aspx

Everytime however no matter what method is used, I cannot get the true
SelectedValue of the drop down list.

All the functions required are inside the ASCX page, there is nothing
needing to be called in the parent ASPX or C# code-behind.

Any ideas?! Thanks in advance!
 
G

Guest

Have you checked If the databinding happening in all postbacks?
The code in Page_load of control should be like below

if(!Page.IsPostBack())
{
yourDDl.datasource =something;
yourDDl.DataBind();
}
 
R

runtoofar

Thanks, I knew it was something simple. Too bad I wasted many hours on
a complex solution not needed!
 
S

Scott Allen

Do you have an event handler for the drop down list's SelectionChanged
event? That would be an ideal spot to pick up the new value - I'm not
sure how data binding will help.
 
Joined
Oct 20, 2011
Messages
1
Reaction score
0
Thank you! had the same problem and it WAS the postback in the page load event that caused the problem.
Thanks again!!
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top