473,387 Members | 1,650 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

How to get value of dynamic DropDownList in User Control ?

Hi all.

I have problem with ASP:DropDownList. I do not know how to get its value.
The DropDownList is populated in Page_Load method (from SQL Server). When
this list is embeded in ASPX page everything runs fine: I can use
Request.Form["DDL_Name"] to know its value.
However, when I use it in control (ASCX) the framework adds something like
"ctl5_:" to the name of the control. So Request.Form[] method does not work.
What is NOT working too, is the SelectedIndexChanged event. This is because
the number of list items is zero at first, so the framework always sets
SelectedIndex to 0.

How to deal with it ?

Regards.

Nov 17 '05 #1
7 2849
Controls which are added dynamically must be re-added and re-populated with
each PostBack. Make sure that you are aware of the Control Execution
Lifecycle when you do this, as the Control must be re-added prior to
processing events. Here is a link to a Microsoft resource on the Control
Execution Lifecycle:

http://msdn.microsoft.com/library/de...nlifecycle.asp

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
http://www.takempis.com
Big Things are made up of
Lots of Little Things.

"Piotr Strycharz"
<Pi**********************@computerplus.krakow.BE Z-SPAMU.pl> wrote in message
news:bl**********@nemesis.news.tpi.pl...
Hi all.

I have problem with ASP:DropDownList. I do not know how to get its value.
The DropDownList is populated in Page_Load method (from SQL Server). When
this list is embeded in ASPX page everything runs fine: I can use
Request.Form["DDL_Name"] to know its value.
However, when I use it in control (ASCX) the framework adds something like
"ctl5_:" to the name of the control. So Request.Form[] method does not work. What is NOT working too, is the SelectedIndexChanged event. This is because the number of list items is zero at first, so the framework always sets
SelectedIndex to 0.

How to deal with it ?

Regards.

Nov 17 '05 #2

Użytkownik "Kevin Spencer" <ke***@DIESPAMMERSDIEtakempis.com> napisał w
wiadomości news:%2****************@TK2MSFTNGP10.phx.gbl...
Controls which are added dynamically must be re-added and re-populated with each PostBack. Make sure that you are aware of the Control Execution
Lifecycle when you do this, as the Control must be re-added prior to
processing events. Here is a link to a Microsoft resource on the Control
Execution Lifecycle:


Well, the controls are not ADDED dynamically (my fault in description), just
the values are. Controls are present at Load. The values are not.

The controls' items are loaded based on the knowledge of values of other
lists. Eg: when I choose "processor" in one control, another control can
have values of "AMD", "Intel", but certainly not "sweet", "salty". However I
cannot generate the other control, because I don't know yet the value of the
previous other controls. Each of the DDLs does depend on the others.
This could be done using Form[...]. However Form[....] does not work in
UserControls.
This cannot be done using .SelectedValue property - because the controls are
not populated yet.

I'm stuck.

Regards.

Piotr.

Nov 17 '05 #3
You don't want to use Request.Form anyway - it defeats the purpose of the
object oriented framework to do that. ASP Classic forced you too, but those
days are finally over. Just use DropDownList.SelectedItem or
DropDownList.SelectedValue, depending on your needs.

--
Chris Jackson
Software Engineer
Microsoft MVP - Windows XP
Windows XP Associate Expert
--
"Piotr Strycharz"
<Pi**********************@computerplus.krakow.BE Z-SPAMU.pl> wrote in message
news:bl**********@nemesis.news.tpi.pl...
Hi all.

I have problem with ASP:DropDownList. I do not know how to get its value.
The DropDownList is populated in Page_Load method (from SQL Server). When
this list is embeded in ASPX page everything runs fine: I can use
Request.Form["DDL_Name"] to know its value.
However, when I use it in control (ASCX) the framework adds something like
"ctl5_:" to the name of the control. So Request.Form[] method does not work. What is NOT working too, is the SelectedIndexChanged event. This is because the number of list items is zero at first, so the framework always sets
SelectedIndex to 0.

How to deal with it ?

Regards.

Nov 17 '05 #4
Instead of Request.Form try this:

ViewState("ControlName")

"Piotr Strycharz"
<Pi**********************@computerplus.krakow.BE Z-SPAMU.pl> wrote in message
news:bl**********@atlantis.news.tpi.pl...

Użytkownik "Kevin Spencer" <ke***@DIESPAMMERSDIEtakempis.com> napisał w
wiadomości news:%2****************@TK2MSFTNGP10.phx.gbl...
Controls which are added dynamically must be re-added and re-populated with
each PostBack. Make sure that you are aware of the Control Execution
Lifecycle when you do this, as the Control must be re-added prior to
processing events. Here is a link to a Microsoft resource on the Control
Execution Lifecycle:


Well, the controls are not ADDED dynamically (my fault in description),

just the values are. Controls are present at Load. The values are not.

The controls' items are loaded based on the knowledge of values of other
lists. Eg: when I choose "processor" in one control, another control can
have values of "AMD", "Intel", but certainly not "sweet", "salty". However I cannot generate the other control, because I don't know yet the value of the previous other controls. Each of the DDLs does depend on the others.
This could be done using Form[...]. However Form[....] does not work in
UserControls.
This cannot be done using .SelectedValue property - because the controls are not populated yet.

I'm stuck.

Regards.

Piotr.

Nov 17 '05 #5
"Tomk20" <to****@hotmail.com> wrote in message
news:u4*************@TK2MSFTNGP10.phx.gbl...
Instead of Request.Form try this:

ViewState("ControlName")


That won't work at all. The ViewState saved by a DropDownList is much more
complicated than just its value.
--
John Saunders
Internet Engineer
jo***********@surfcontrol.com
Nov 17 '05 #6

Użytkownik "Chris Jackson" <ch****@mvps.org> napisał w wiadomości
news:er*************@tk2msftngp13.phx.gbl...
You don't want to use Request.Form anyway - it defeats the purpose of the
object oriented framework to do that. ASP Classic forced you too, but those days are finally over. Just use DropDownList.SelectedItem or
DropDownList.SelectedValue, depending on your needs.


O dear...
This is the third time I say: I have NO access to these properties, because
the DropDownLists at Page.Load are EMPTY. These values are "" and 0.
Also I cannot load them before I read their values.

Regards.

Piotr.

Nov 17 '05 #7
It's the same principle. In fact, a ListItem is a Control as well. So, you
need to re-add the ListItems to the DropDownList prior to processing the
Events.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
http://www.takempis.com
Big Things are made up of
Lots of Little Things.

"Piotr Strycharz"
<Pi**********************@computerplus.krakow.BE Z-SPAMU.pl> wrote in message
news:bl**********@atlantis.news.tpi.pl...

Użytkownik "Kevin Spencer" <ke***@DIESPAMMERSDIEtakempis.com> napisał w
wiadomości news:%2****************@TK2MSFTNGP10.phx.gbl...
Controls which are added dynamically must be re-added and re-populated with
each PostBack. Make sure that you are aware of the Control Execution
Lifecycle when you do this, as the Control must be re-added prior to
processing events. Here is a link to a Microsoft resource on the Control
Execution Lifecycle:


Well, the controls are not ADDED dynamically (my fault in description),

just the values are. Controls are present at Load. The values are not.

The controls' items are loaded based on the knowledge of values of other
lists. Eg: when I choose "processor" in one control, another control can
have values of "AMD", "Intel", but certainly not "sweet", "salty". However I cannot generate the other control, because I don't know yet the value of the previous other controls. Each of the DDLs does depend on the others.
This could be done using Form[...]. However Form[....] does not work in
UserControls.
This cannot be done using .SelectedValue property - because the controls are not populated yet.

I'm stuck.

Regards.

Piotr.

Nov 17 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Piotr Strycharz | last post by:
Hi all. I have problem with ASP:DropDownList. I do not know how to get its value. The DropDownList is populated in Page_Load method (from SQL Server). When this list is embeded in ASPX page...
5
by: mytestemailaccount | last post by:
Hi, Hope you can help. I am relatively new to all this but would appreciate the groups help. The scenario: I am c# and asp.net to create a web application. The web page contains a user...
1
by: amirmira | last post by:
I have a multithreaded application is ASP.NET that checks the status of a process every 2 seconds. After the thread has completed, the values of dynamically added controls need to be changed...
7
by: John | last post by:
Hi all, I need finality on this once and for all please. I have a main page which contains a couple of placeholders and within these placeholders, depending on what the user presses, I load...
5
by: Nathan Sokalski | last post by:
I have a user control that contains three variables which are accessed through public properties. They are declared immediately below the "Web Form Designer Generated Code" section. Every time an...
6
by: Nathan Sokalski | last post by:
I am writing a User Control that uses 3 DropDownLists. When I attempt to access the SelectedIndex property it incorrectly reports the value selected by the user. Why is this? Here is my code,...
2
by: Developer_Software | last post by:
Thanks in advance to anyone who can help :) I've got a placeholder control WITHIN A USER CONTROL that has its contents dynamically added and removed at runtime by a regular .aspx page. At...
0
by: imranabdulaziz | last post by:
hi all , i am mess with the one situation. i am using asp.net2.0 ,C# and sql server 2005. I have checkboxlist and based on user selection i creates dynamic controls(which code is in...
4
Frinavale
by: Frinavale | last post by:
Introduction Sometimes, when developing web applications, we need to be able to dynamically load controls based on user selections. The following article describes a simple scenario where TextBox...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.