Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > How to get value of dynamic DropDownList in User Control ?

Reply
Thread Tools

How to get value of dynamic DropDownList in User Control ?

 
 
Piotr Strycharz
Guest
Posts: n/a
 
      09-29-2003
Hi all.

I have problem with ASPropDownList. 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.

 
Reply With Quote
 
 
 
 
Kevin Spencer
Guest
Posts: n/a
 
      09-29-2003
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"
<(E-Mail Removed)-SPAMU.pl> wrote in message
news:bl9bef$8ec$(E-Mail Removed)...
> Hi all.
>
> I have problem with ASPropDownList. 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.
>



 
Reply With Quote
 
 
 
 
Piotr Strycharz
Guest
Posts: n/a
 
      09-29-2003

Użytkownik "Kevin Spencer" <(E-Mail Removed)> napisał w
wiadomości news:%(E-Mail Removed)...
> 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.

 
Reply With Quote
 
Chris Jackson
Guest
Posts: n/a
 
      09-29-2003
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"
<(E-Mail Removed)-SPAMU.pl> wrote in message
news:bl9bef$8ec$(E-Mail Removed)...
> Hi all.
>
> I have problem with ASPropDownList. 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.
>



 
Reply With Quote
 
Tomk20
Guest
Posts: n/a
 
      09-29-2003
Instead of Request.Form try this:

ViewState("ControlName")





"Piotr Strycharz"
<(E-Mail Removed)-SPAMU.pl> wrote in message
news:bl9hv7$c8q$(E-Mail Removed)...
>
> Użytkownik "Kevin Spencer" <(E-Mail Removed)> napisał w
> wiadomości news:%(E-Mail Removed)...
> > 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.
>



 
Reply With Quote
 
John Saunders
Guest
Posts: n/a
 
      09-29-2003
"Tomk20" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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
http://www.velocityreviews.com/forums/(E-Mail Removed)


 
Reply With Quote
 
Piotr Strycharz
Guest
Posts: n/a
 
      09-30-2003

Użytkownik "Chris Jackson" <(E-Mail Removed)> napisał w wiadomości
news:(E-Mail Removed)...
> 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.

 
Reply With Quote
 
Kevin Spencer
Guest
Posts: n/a
 
      09-30-2003
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"
<(E-Mail Removed)-SPAMU.pl> wrote in message
news:bl9hv7$c8q$(E-Mail Removed)...
>
> Użytkownik "Kevin Spencer" <(E-Mail Removed)> napisał w
> wiadomości news:%(E-Mail Removed)...
> > 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.
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
placement of dynamic control depends on VALUE of dynamic control Larry Bud ASP .Net 1 01-10-2007 10:07 PM
Dynamic creation of a user control with a dropdownlist Hugo Flores ASP .Net 1 09-06-2006 02:33 AM
How do I get the value of a DropDownList control that was defined by customizing the CreateUserWizard control? Learner ASP .Net Security 2 04-25-2006 08:19 PM
User Control Dropdownlist: can't assign value to JJ_377@hotmail.com ASP .Net 0 07-22-2005 12:17 AM
Help!! how to get the value of dynamic web user control? hb ASP .Net 2 04-13-2004 12:44 AM



Advertisments