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();

_chkList.ID = "DDList";

_chkList.BorderColor = Color.White;

_chkList.BorderStyle = BorderStyle.Solid;

_chkList.Width = Unit.Percentage(100);

strItems = List;

StrArrItem = strItems.Split(cSplitChar);

intLegth = StrArrItem.Length;


for (int i = 0; i < intLegth; i++)







public string List





strValue = ViewState[
if (strValue.Length > 0)


strValue = strValue.Length > 0 ? strValue.Substring(0, strValue.Length - 1) : strValue;



return strValue;




"Value"] = null;

strValue += value + ",";

ViewState["Value"] = strValue;




Can anybody help me pleaseeeeSad

1/20/2009 4:46:17 AM 93655 articles. 3 followers. Follow

1 Replies

Similar Articles

[PageSpeed] 41

May be this link will help you..

My Blog

"Don't be afraid to be wrong; otherwise you'll never be right."
1/20/2009 5:32:38 AM

Similar Artilces:

How to preserve values in a web form when navigating to a different page and then going back to the original page using the back button ?
   I am working on a C#/ASP.NET web application. The web application basically consist of 3 web forms. Each form contains several controls such as an edit box, and some drop down list box controls. Basically I need to find out how to preserve the values in a web form when a person navigates to a different page. For example, suppose that in my web application I navigate from my first page (First.aspx) to my second page (Second.aspx). Now if I press the browsers back button, I want the application to retain the values for the controls that were in my first web form "first....

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.ToStrin...

Getting undefined value while using view state in Web Form Designer generated code
hi,    i am trying to get the drop down list selected value in Web Form Designer generated code,when i am trying it with view state i am getting some undefined value.please help me regarding this.. i am trying with the following code.        refinery =  ddRefineries.SelectedRefinery; ViewState.Add("ref1",refinery); #region Web Form Designer generated code        override protected void OnInit(EventArgs e)        {          &nbs...

How to preserve the value of a form field when the user press a "BACK" button on my web page?
Hi all,  I have 3 forms with some text fields and checkboxes. I move from Form1 to Form2, and then to Form3. I use session variables to pass values between forms. Now the problem is, when I am in Form3, when the user clicks a "BACK" button on Form3, he should be taken to Form2. At this stage, the data he entered on Form2 should be there as it was! For this, should I load back the values of each field from the session variables? Or is there any automated method to do this (may be from the viewstate etc.)? Can anyone help me? Thanking you in advance, Tomy Viewstate works onl...

Could PB .NET Web Form POST security Information to others web page??
This is a multi-part message in MIME format. ------=_NextPart_000_00F9_01C9C4D5.8FB45C90 Content-Type: text/plain; charset="big5" Content-Transfer-Encoding: quoted-printable Hi,=20 Have anyone came across the requesion to POST security informations from = PB .NET web form web page to other web site?? I have tried many datys, Could any kind man give me some suggessions?? thanks & Best regards Leon ------=_NextPart_000_00F9_01C9C4D5.8FB45C90 Content-Type: text/html; charset="big5" Content-Transfer-Encoding: quoted-printable <!DOCTYPE HTML P...

FORM values on post back
 okay... another dumb nubie question here... I am building a form with three dropdown controls to drill down through category, sub-category and product. I have each set to post back so that when the user selects the main category the sub-category  should be populated  based on the value of  the main control. The controls (or at least the first one) are binding to a WebService class. But or some crazy reason I can't seem to access the value of the main category to supply it to the sub category WebService. However the selected value of the main category is mai...

Passing Values from a Web Form to Another Web Form
Hello All! I am trying to pass values from one web form to another web form. I know that there are 3 ways of doing this: queryString, Server.Transfer and Session. I am using the Server.Transfer method. But I am not able to create, in my 2nd web form, an instance of my 1st web form. My 1st Web form is named CallTrack.aspx and my 2nd is named Export.aspx. What I mean is something like this: Public value as CallTrack. I can't create it in my 2nd web form because when the intellisense is displayed, there's no CallTrack in the options. Thanks!   How about using cross-...

Web form debugging
Hi, This is SOS call, since I have no idea what happend, but my web page is not working any more though I didn't change a thing. I have a web page, containing datagrid, dataset, and listbox. The user chooses an item from the listbox, push the button, and get the relevant records in the datagrid.  I added another feature: "quick search" containing textbox and another button, and when the user type something in the textbox and push the button, the datagrid being populated from the new search algorithm instead of the listbox. Every thing was working perfect, till I changed something, a...

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 What exactly are you trying to do. Can you be more explicable?Shravan Addaypally MCP...

Implementing .Net Form into an web form, can this be done
I am new here, but have been searching for a while, and may not have the correct lingo to find what I am looking for.  I am tasked with implementing a .exe application that was writen vb6 then converted to .net into a new website my team is developing. The idea is to put each of the 3 different forms in this .exe application of 3 different .aspx pages. I have attempted multiple things to get this into the page and even started to just rewrite it as an web form, but even then I can't reuse any of the code since the System.Web.UI.Page doesn't inherit the sa...

Prevent browser refreshes from posting back an already-posted-back form?
HiI have a formview in insert mode for inserting items into a gridview.  Each item is some description text, a price, and a quantity.  I'm using SqlDataSource controls while I learn about the New Way of Doing Things.If I insert an item, and then refresh the now-posted-back page in my browser, the same item gets inserted again.  I would like to prevent this, ideally without response.redirecting on FormView.ItemInserted every time a new item is inserted.  I don't think it'd be a question of clearing the inputs and validating for data, would it?  I mean, an F5 will repo...

Passing value from details view to other web form
Hi, I am using the Grid view and for details I am using the details view. Now my situation is that I need to paas the value to other web form. So how can I pass the value from details view to other web form. you can either use query string or store the value into session and retieve it on the other pageSriPlease mark as answer if it helped you Hey, I am using the querystring, but how can I do that. Here is my query string, inthe details view. <SelectParameters> <asp:QueryStringParameter Name="JobID_I" QueryStringField="ID" Type="Int64" />...

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 ...

DropDownList value not post back in ajax form
I encountered a bug with ajax form with DropDownList.The selected value in DropDownList can't be posted to web server.This bug only appears in IE (mine is 7.0.5730.11), but not in FF / chrome.  Here is the sample code // *************** CONTROLLER  ***************         public ActionResult Test(int? page)        {            return View();        } // *************** CONTROLLER  *...