473,395 Members | 1,584 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

ViewState of items in custom TextBoxList not maintained after postback

Hai Friends;
I have a custom TextBoxlist which inherits the listcontrol but the problem is that
the items in the listcontrol which are textboxes donot maintain viewstate after postback and the initial values are being loaded everytime.I have overridden the
loadviewstate and saveviewstate methods and saved the listitem values that is text in textboxes in saveviewstate method but those values donot seem to have
saved.

Please try to give me a solution

The complete code in code-behind is below.

Expand|Select|Wrap|Line Numbers
  1.  
  2. public class TextBoxList:ListControl,IRepeatInfoUser
  3.     {
  4.         private TextBox controlToRepeat;
  5.  
  6.         public TextBoxList()
  7.         {
  8.             this.controlToRepeat = new TextBox();
  9.             this.controlToRepeat.ID = "0";
  10.             this.controlToRepeat.EnableViewState = false;
  11.             this.Controls.Add(this.controlToRepeat);
  12.         }
  13.  
  14.         protected override object SaveViewState()
  15.         {
  16.             object[] state = new object[this.Items.Count];
  17.  
  18.             for (int i = 0; i < this.Items.Count; i++)
  19.             {
  20.                 state[i] = this.Items[i].Text;
  21.             }
  22.  
  23.             return state;
  24.         }
  25.  
  26.         protected override void LoadViewState(object savedState)
  27.         {
  28.             if (savedState == null) return;
  29.  
  30.             if (savedState is object[])
  31.             {
  32.                 object[] state = (object[])savedState;
  33.  
  34.                 for (int i = 0; i < state.Length; i++)
  35.                 {
  36.                     this.Items[i].Text = state[i].ToString();
  37.                 }
  38.             }
  39.             else
  40.                 base.LoadViewState(savedState);
  41.         }
  42.  
  43.         protected override void Render(HtmlTextWriter writer)
  44.         {
  45.             RepeatInfo info1 = new RepeatInfo();
  46.             Style style1 = base.ControlStyleCreated ? base.ControlStyle : null;
  47.             info1.RepeatColumns = 1;
  48.             info1.RepeatDirection = RepeatDirection.Vertical;
  49.             info1.RepeatLayout = RepeatLayout.Table;
  50.             info1.RenderRepeater(writer, this, style1, this);
  51.  
  52.         }
  53.  
  54.         public bool HasHeader
  55.         {
  56.             get
  57.             {
  58.  
  59.                 return false;
  60.             }
  61.         }
  62.  
  63.         public bool HasSeparators
  64.         {
  65.             get
  66.             {
  67.  
  68.                 return false;
  69.             }
  70.         }
  71.  
  72.         public bool HasFooter
  73.         {
  74.             get
  75.             {
  76.  
  77.                 return false;
  78.             }
  79.         }
  80.  
  81.         public void RenderItem(System.Web.UI.WebControls.ListItemType itemType, int repeatIndex, RepeatInfo repeatInfo, HtmlTextWriter writer)
  82.         {
  83.     this.controlToRepeat.ID = repeatIndex.ToString(NumberFormatInfo.InvariantInfo);
  84.             this.controlToRepeat.Text = this.Items[repeatIndex].Text;
  85.             this.controlToRepeat.RenderControl(writer);
  86.         }
  87.  
  88.         public Style GetItemStyle(System.Web.UI.WebControls.ListItemType itemType, int repeatIndex)
  89.         {
  90.  
  91.             return null;
  92.         }
  93.  
  94.         public int RepeatedItemCount
  95.         {
  96.             get
  97.             {
  98.  
  99.                 return this.Items.Count;
  100.             }
  101.         }
  102.  
  103.     }
  104.  
  105.  


ThankYou
vijay
Dec 4 '07 #1
0 898

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Lloyd Sheen | last post by:
I have a page that works fine. I am trying to optimize the page by overriding some of the Information that is being saved in the hidden VIEWSTATE. If I make the properties of the dropdown False...
10
by: neo | last post by:
hi, I am studying ASP.NET and have few questions - 1) The session ID and values of controls is stored in VIEWSTATE variable. So now when we put EnableViewState="false" in Page directive and...
2
by: Jay Walker | last post by:
I created a custom DataGridColumn based on Marcie Robillard's MSDN Article: Creating Custom Columns for the ASP.NET Datagrid...
3
by: Chris Newby | last post by:
I have a very simple custom control that derives from WebControls.Panel and implements INamingContainer. It appear that controls created as children of my custom control are having ViewState...
0
by: Chris Newby | last post by:
I have a custom control that is essentially implemented as follows: ================================================ public class TestPanel : WebControl, INamingContainer { protected override...
2
by: fabrice | last post by:
Hi, I have a trouble with my TextBox Control and it's ViewState in my form... The property for it, is FALSE as following : <form id="frmSearchBre4" runat="Server"> <asp:textbox id="myID"...
10
by: Robert | last post by:
I have an app that was originally 1.1, now migrated to 2.0 and have run into some sporadic viewstate errors...usually saying the viewstate is invalid, eventvalidation failed or mac error. My web...
3
by: Justin | last post by:
I have aspx pages with 10 checkboxlist controls. total individual checkbox (the sum of individual checbox in those 10 checkboxlists) on the page is about 1710. You can imagine how large the...
0
by: webmaster | last post by:
Hi all, I'm tearing my hair out with this one. I have successfully implemented by own RadioButtonList in order to provide additional functionality and a DIV rather than TABLE-based layout in...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.