what data is stored of DropDownList control form view state when post back?

hello!

As we know , the view state is not responsible for having TextBoxes, CheckBoxes, DropDownLists, and other Web controls remember their values across postback.

When I dynamically add a DropDownList in the web,and dynamically add the items in it.

such as:

void Page_Load(Object sender, EventArgs e)
{
   DropDownList ddlDynamic = new DropDownList();
   ddlDynamic.ID = "ddlDynamic";

   form1.Controls.Add(ddlDynamic);

   if (!IsPostBack)
   {
 for (int i=1; i <=3; i++)
  ddlDynamic.Items.Add(new ListItem(i.ToString(), i.ToString()));
   }

I check the second value of the DropDownList.

when post back ,I can see the dynamically items,and the checked value is what I have checked.

My question is :what data is stroed in view sate,and where the checked data is stored .

0
gorilorzhang
5/21/2007 1:02:31 AM
asp.net.state-management 8807 articles. 0 followers. Follow

5 Replies
973 Views

Similar Articles

[PageSpeed] 40

HI, gorilorzhang : 

When a Web server control is created dynamically at run time, some information about the control is stored in the view state that is rendered with the page. When the page is posted back to the server, however, non-dynamic controls (those defined on the page) are instantiated in the page's Init event and view state information is loaded before the dynamic controls can be recreated (generally in the Page_Load handler). Effectively, before the dynamic controls are recreated, view state is temporarily out of sync with the page's controls. After the Page_Load event has run, but before control event-handling methods are called, the remaining view state information is loaded into the dynamically created controls.

In most scenarios, this view state processing model works fine. Typically, you add dynamic controls to the end of a container's collection of controls. The view state information stored for the dynamic controls is therefore extra information at the end of the view state structure for the appropriate container, and the page can ignore it until after the controls are created.

If you reinsert controls with each round trip, each generation of dynamically created controls will pick up property values from the view state of the preceding set of controls.

I hope the above information will be helpful. If you have any issues or concerns, please let me know. It's my pleasure to be of assistance
 

 


Best Regards,
__________________________________________________
Sincerely,
Rex Lin
Microsoft Online Community Support

If there is any question or the issue is not resolved, please feel free to mark the thread as not resolved
0
Rex
5/22/2007 2:44:26 AM

hello Rex Lin  

I can conclude from your article:

in the Page_Load event of my code,the items information of the DropDownList can be load after the DropDownList is recreated.but the check value is not stored in the view state,how is it loaded after the DropDownList recreated.

thank you.

0
gorilorzhang
5/23/2007 1:14:42 AM

HI, gorilorzhang : 

when you're doing it relative to the Controls.Add(dynamicControl) line. You may be able to get away with loading your controls in the Page_Load event handler and maintaining the view state properly,the reason it may work is because the Controls property's Add() method recursively loads the parent's view state into its children, even though the load view state stage has passed.

When adding a dynamic control c to some parent control p based on some condition (that is, when not loading them on each and every page visit), you need to make sure that you add c to the end of p's Controls collection. The reason is because the view state for p contains the view state for p's children as well,, p's view state specifies the view state for its children by index.

More details:

Understanding ASP.NET View State

http://msdn2.microsoft.com/en-us/library/ms972976.aspx

I hope the above information will be helpful. If you have any issues or concerns, please let me know. It's my pleasure to be of assistance

 


Best Regards,
__________________________________________________
Sincerely,
Rex Lin
Microsoft Online Community Support

If there is any question or the issue is not resolved, please feel free to mark the thread as not resolved
0
Rex
5/23/2007 1:42:09 AM

Hi Rex Lin:

thanks for your help with view state,but I still puzzle about one thing,

The check value of  the DropDownList is not stored in the view state.but the checked value is loaded when post back,in the life cycle of the control ,the load post back data stage is before the Page_Load event,that is when load post back data ,the DropDownList is not recreated,how does it be loaded?

0
gorilorzhang
5/23/2007 7:42:32 AM

HI, gorilorzhang : 

Because the container has got the viewstate of the child control,you may be able to get away with loading your controls in the Page_Load(after the load viewstate) event handler and maintaining the view state properly,the reason it may work is because the Controls property's Add() method recursively loads the parent's view state into its children, even though the load view state stage has passed.


Best Regards,
__________________________________________________
Sincerely,
Rex Lin
Microsoft Online Community Support

If there is any question or the issue is not resolved, please feel free to mark the thread as not resolved
0
Rex
5/23/2007 8:12:02 AM
Reply:

Similar Artilces:

populating a dropdownlist of states based on selection of country in dropdownlist and populating a dropdownlist of cities based on selection state in state dropdownlist
My code is this but i m not getting states in dropdownlist of states based on selection of country and  cities based on selection of state <%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" > <head runat="server"><title>Untitled Page</title> </head> <...

how to store data in state server mode of session state
How do I store and retrieve data in state server mode of session state? How do i increase integer in label control when user adds item in shopping cart? for ex (2) items added. when the user adds a third item the label control should say (3) items added. Thank you, Farhan Hi,You do not have to do anything special in your code You can use the Session object in the normal way and need not do anything. ASP .Net handles it behind the scenes.Store your variables using the session object like, Session("Items") = 5  and so onHibrihttp://www.hibri.net...

State Management : Data Stored in Application
Hello, I'm in the process of migrating an ASP.NET 1.1 site to 2.0. One of the problem I encounter is the change of behavior of the framework calling "Application_Start" in global.asax.cs. Basically : 1) Issue an IISRESET to make sure to start from scratch. 2) Access a page in the site : "Application_Start" is called. During this call, I check database access and other few things and store the database state in the application cache. 3) Wait until the ASP.NET process is recycled due to inactivity. 4) Access the site again. "Application_Start is not called", so Application cache is mi...

State management form post problem
Hi everyone! This is my first post at asp.net. I'm developing a web application using MVC and I have a doubt. There's a page named "My Account" where the user can edit his data (change his phone, address etc). So, this page gets all the user data from the database and fills all TextBox, DropDownList etc dynamically. To do this (gets data from DB), I use: 1    [Accept(Http.verbs.Get)]2    public ActionResult UserDetail3    (...)4    ViewData["nome"] = u.nome;5    ViewData["sexo&q...

how to save the View state and post back of ...
How to save the View state and post back of control added to TableCell.I adding the  control to the TableCell and lose the data, the checked not checked and other things.any one know how to handle the TableCell to not lose the controls in it (property)?Ido Yahalomi,.NET Architect www.reptor.com. What exactly are you trying to do. Can you be more explicable?Shravan Addaypally MCP...

superreview requested: [Bug 285285] Add SINGLE_LINE state to single line text inputbox : [Attachment 176741] Clean up form control and text field state code, add single line extended state support
Louie Zhao <Louie.Zhao@sun.com> has asked Henry Jia <Henry.Jia@sun.com> for superreview: Bug 285285: Add SINGLE_LINE state to single line text inputbox https://bugzilla.mozilla.org/show_bug.cgi?id=285285 Attachment 176741: Clean up form control and text field state code, add single line extended state support https://bugzilla.mozilla.org/attachment.cgi?id=176741&action=edit ...

superreview granted: [Bug 285285] Add SINGLE_LINE state to single line text inputbox : [Attachment 176741] Clean up form control and text field state code, add single line extended state support
Henry Jia <Henry.Jia@sun.com> has granted Louie Zhao <Louie.Zhao@sun.com>'s request for superreview: Bug 285285: Add SINGLE_LINE state to single line text inputbox https://bugzilla.mozilla.org/show_bug.cgi?id=285285 Attachment 176741: Clean up form control and text field state code, add single line extended state support https://bugzilla.mozilla.org/attachment.cgi?id=176741&action=edit ...

session vs caching vs control state vs view state
difference between session and cache and view state and control state which is used at what time and for what purpose exactly Hi,this article explains it the best: ASP.NET: Nine Options for Managing Persistent User State in Your ASP.NET Application.Grz, Kris.  Read my blog. Handy Firefox plugins for web developers.Workaround for non working Mark as answer buttons....

Validating States dropdownlist with all other validation controls on form?
I have States dropdownlist  starts with "--" ListItem and 50 States. If user select "--" first ListItem, I need validate at client. Right now I am doing code behind side validation. But I have other controls on the form for validation, So I need to validate all at time. on submit button click.   Hi Srikanth, Place a required field for states dropdown list and set the "intial value" property of required field validator to "--". On Submit click validation is done. Above is the solution if i am not misunderstood you.   Regards, Pra...

Preserve View State value at post back
Hi All,    I am creating a custom server control.That control contains a check box list. For the first time I am getting value for that check box list, at run time through Get/Set property. In Property I am using View state for setting value. While page is post back, the view state is getting null. How can I preserve the value of view state. Sample code is as follows,  private CheckBoxList _chkList;protected override void CreateChildControls() {string strItems; string[] StrArrItem = null;char cSplitChar = ','; int intLegth = 0;_chkList = new CheckBoxList(...

View state and loading drop down on post back.
The page contains 6 drop downs with many values resulting in very big view state. So I disabled view state of all drop down and filled drop down on every post back.  Now the problem is as view state is disabled and drop downs are being filled on each post back, they are not retaining their selected value on post back. Also filling drop down on page load method is resulting in overrating selected value and getting always 0 as selected value in button click event.  Do I need to make view state enabled here? Hi, yes, you need to enable the view state. Each DropDownList in your ...

Usage scenarios for view state, session state, application state, cookies
Hi Guys, Im a college student in London with exams starting Monday on ASP.NET with C#.  Id be so grateful if you could provide me with solid real world scenarios/examples of when you would use the following to maintain state and why you would use them in that instance:   View State Session State Application State Cookies Also when would you use SOAP instead of the REST architecture and vice versa and why - again real world usage scenarios?  I note Amazon's web service uses the REST architecture - why is this, why dont they use SOAP. Id be grateful for a timely respon...

Session State and View State
Hi Everyone, Can anybody tellme how are these used in context with ASP.NeT whats their sole purpose?.....and where in programming we use  them? Any links or sources would be good which explains in simple terms.   thanks Simi  ThanksSimi------------&------------"To learn to succeed, you must first learn to fail." -Michael Jordan Here is one of the discussion http://forums.asp.net/t/1145838.aspxMPI never desire to converse with a man who has written more than he hasread. -Samuel Johnson, lexicographer (1709-1784)  Hi There is a video tutorial a...

Issue with ratings control saving it's state in the view state when created dynamically.
I want to create ratings control dynamically and get the CurrentRating during a button click.I modified the AjaxControlToolkit Ratings Control example to use a placeholder <asp:PlaceHolder ID="phRating" runat="server"></asp:PlaceHolder> and .... EnableViewState="True" and the following new code:Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.LoadDim objRating As New AjaxControlToolkit.RatingobjRating.ID = "LikeRating"objRating.MaxRating = 5objRating.CurrentRating = 2objRating.StarCssClass = "r...

Web resources about - what data is stored of DropDownList control form view state when post back? - asp.net.state-management

Tag Synonyms - Stack Overflow
Q&A for professional and enthusiast programmers

Accidental entities - what about the UI?
This post is a follow-up to my previous blog post " Accidental entities - you don't need that identity ". In that post, we followed a consultant ...

Flash Builder Plug-in for SAP Netweaver Gateway - Adobe Labs
Search Navigation Labs Home Wiki Home Technologies Alchemy Blueprint Camera Profiles and DNG Profile Editor Cirrus ColdFusion 10 DNG Codec Fireworks ...

Air Astana - Join Now
Thank you for considering membership of Nomad Club – Kazakhstan’s first Frequent Flyer Program. You could soon be on your way to earning free ...

Languages -> C# Articles, Tutorials, Examples: ASP Alliance
.NET,ASP,ASP.NET,SQL,XML,HTML,ADO,ADO.NET,JavaScript,JScript,CSharp,VBScript and VB tutorials from AspAlliance.

Blog - Avisra
Avisra Web Development Home Blog Services Contact The Blog Latest Module Builder: How can we make it better? Sitefinity by Chris on July 2, 2013 ...

Online Booking Tool Support
This Online Booking Tool Support page might help you as you navigate through the process of booking travel through your OBT provided by CWT. ...

@Html and beyond
... ); } return string .Format( “{0}{1}” , me.Member.Name, id); } The Html building methods are quite simple. Building a dropdownlist for a ...

Top Ranked Articles
Top Ranked Articles - Free source code and tutorials for Software developers and Architects.; Updated: 23 Feb 2013

Unit Testing DateTime.Now Without Isolation
public virtual void SeedWithYearsSince(DropDownList list, int year){ for (int index = year; index

Resources last updated: 1/16/2016 4:40:12 PM