?
Solved

Dynamically Generated DropDownList in GridView Lose Selected Values On PostBack

Posted on 2008-02-01
3
Medium Priority
?
1,311 Views
Last Modified: 2013-11-07
I'm generating dropwdownlists(ddl) in a gridview using ITemplate. When selections are made in the ddls
and the form is submitted the form builds before the OnRowCommand or submit button event handlers are fired. How can I access the the selected values on PostBack?
0
Comment
Question by:wsmith5204
  • 2
3 Comments
 
LVL 18

Accepted Solution

by:
Joel Coehoorn earned 2000 total points
ID: 20799861
Whenever you have a dynamically generated control of any type that loses state on postback, it almost always comes down to a page lifecycle problem.

In a nutshell, your page is recreated from scratch every time it reloads, including on postback.  This means you have to re-create your dynamic controls as well.  One of the things that happens while the page loads is to bind state information for each control on the page.  However, it can only do this if the control already exists at that point in the life cycle.  So what's likely happening is that you aren't re-creating your dynamic control early enough in the page lifecycle for the state information get loaded.

These links really helped me understand the problem when I first ran into it:
http://aspnet.4guysfromrolla.com/articles/081402-1.aspx
http://aspnet.4guysfromrolla.com/articles/092904-1.aspx
0
 

Author Comment

by:wsmith5204
ID: 20800053
I'm generating the controls in the OnInit() method. Is the an earlier point in the page lifecycle I can generate them (pre-init)?
0
 
LVL 18

Expert Comment

by:Joel Coehoorn
ID: 20800381
IIRC, OnInit is the correct place, ASP.Net 2.0 has a PreInit, and ASP.Net 1.1 does not.  
0

Featured Post

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
In real business world data are crucial and sometimes data are shared among different information systems. Hence, an agreeable file transfer protocol need to be established.
How can you see what you are working on when you want to see it while you to save a copy? Add a "Save As" icon to the Quick Access Toolbar, or QAT. That way, when you save a copy of a query, form, report, or other object you are modifying, you…
The video will let you know the exact process to import OST/PST files to the cloud based Office 365 mailboxes. Using Kernel Import PST to Office 365 tool, one can quickly import numerous OST/PST files to Office 365. Besides this, the tool also comes…
Suggested Courses
Course of the Month5 days, 9 hours left to enroll

589 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question