DotNetNewsgroup.com  
web access to complete list of Microsoft.NET newsgroups
   home   |   control panel login   |   archive  |  
 
  carried group
academic
adonet
aspnet
aspnet.announcements
aspnet.buildingcontrols
aspnet.caching
aspnet.datagridcontrol
aspnet.mobile
aspnet.security
aspnet.webcontrols
aspnet.webservices
assignment_manager
datatools
dotnet.distributed_apps
dotnet.general
dotnet.myservices
dotnet.nternationalization
dotnet.scripting
dotnet.security
dotnet.vjsharp
dotnet.vsa
dotnet.xml
dotnetfaqs
framework
framework.clr
framework.compactframework
framework.component_services
framework.controls
framework.databinding
framework.drawing
framework.enhancements
framework.interop
framework.odbcnet
framework.performance
framework.remoting
framework.sdk
framework.setup
framework.webservices
framework.windowsforms
framework.wmi
frwk.windowsforms.designtime
lang.csharp
lang.jscript
lang.vb
lang.vb.controls
lang.vb.data
lang.vb.upgrade
lang.vc
lang.vc.libraries
  
 
start date: Thu, 2 Aug 2007 20:44:01 -0700,    posted on: microsoft.public.dotnet.framework.aspnet        back       

Thread Index
  1    Dave
          2    Manish Bafna
          3    Eliyahu Goldin


get value of dynamic control on postback?   
For simplicity sake,

How do you get the value of selected dropdown on a postback?  I understand 
for a dynamic control, you need to re-create it on each postback, but how do 
I modify the code to grab the SelectedValue?  

protected void Page_Load(object sender, EventArgs e)
{
        DropDownList list = new DropDownList();
        list.ID = "DropDownList1";
        list.Items.Add(new ListItem("1", "One"));
        list.Items.Add(new ListItem("2", "Two"));
        list.Items.Add(new ListItem("3", "Three"));
        PlaceHolder1.Controls.Add(list);      
}
Date:Thu, 2 Aug 2007 20:44:01 -0700   Author:  

RE: get value of dynamic control on postback?   
Hi,
So, the controls that were dynamically created are no longer there and 
consequently the values returned from these controls have no place to go. 
They are lost in the viewstate. 

In order to catch these values the dynamically generated controls needs to 
be re-generated at Page_Load. The important thing is to assign the same ID to 
each control. The ViewState uses the ID property of the Control objects to 
reinstate the values. 

If you create a dynamic dropdownlist, conditionally, say in response to some 
other control's click event. Then, on PostBack, you recreate a "new" dropdown 
with the same object name, then "magically" that new dropdown becomes the 
dynamically-created dropdown. You get all of the user-initiated and 
code-generated properties.
ref:http://www.codeproject.com/aspnet/retainingstate.asp?df=100&forumid=14609&exp=0&select=1495875
-- 
Hope this answers your question.
Thanks and Regards.
Manish Bafna.
MCP and MCTS.



"Dave" wrote:


> For simplicity sake,
> 
> How do you get the value of selected dropdown on a postback?  I understand 
> for a dynamic control, you need to re-create it on each postback, but how do 
> I modify the code to grab the SelectedValue?  
> 
> protected void Page_Load(object sender, EventArgs e)
> {
>         DropDownList list = new DropDownList();
>         list.ID = "DropDownList1";
>         list.Items.Add(new ListItem("1", "One"));
>         list.Items.Add(new ListItem("2", "Two"));
>         list.Items.Add(new ListItem("3", "Three"));
>         PlaceHolder1.Controls.Add(list);      
> }
>               
Date:Thu, 2 Aug 2007 22:02:03 -0700   Author:  

Re: get value of dynamic control on postback?   
Place the code for control creting in the PreInit event. The reason is
because LoadViewState occurs between Init and Load events.

-- 
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin


"Dave"  wrote in message
news:462AB8FC-3F2A-40CF-9920-119F5A6C9224@microsoft.com...

> For simplicity sake,
>
> How do you get the value of selected dropdown on a postback?  I understand
> for a dynamic control, you need to re-create it on each postback, but how
do
> I modify the code to grab the SelectedValue?
>
> protected void Page_Load(object sender, EventArgs e)
> {
>         DropDownList list = new DropDownList();
>         list.ID = "DropDownList1";
>         list.Items.Add(new ListItem("1", "One"));
>         list.Items.Add(new ListItem("2", "Two"));
>         list.Items.Add(new ListItem("3", "Three"));
>         PlaceHolder1.Controls.Add(list);
> }
>
Date:Fri, 3 Aug 2007 09:19:41 +0200   Author:  

Google
 
Web dotnetnewsgroup.com


COPYRIGHT ?2005, EUROFRONT WORLDWIDE LTD., ALL RIGHT RESERVE  |   Contact us