473,395 Members | 1,689 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 ?

Hello group,

I am trying to do something simple (or so do I think). A web page, with a
Button, each click on it adding a row in a Table below. The result I get is
that the Table always has only one row (the one I'm trying to add), instead
of getting one *more* row after each click. I thought ViewState would keep
my Table as it was and really add the row ?

Here is my Table in the .aspx :

<asp:Table id="tbl" Runat="server" Visible="False">
<asp:TableRow>
<asp:TableHeaderCell Text="Col1" />
<asp:TableHeaderCell Text="Col2" />
<asp:TableHeaderCell Text="Col3" />
</asp:TableRow>
</asp:Table>

and here is the code behind for the button :

TableRow row = new TableRow();
TableCell cell = new TableCell();
cell.Text = "<some computed text>";
row.Cells.Add(cell);
cell = new TableCell();
cell.Text = "<some computed text>";
row.Cells.Add(cell);
cell = new TableCell();
cell.Text = "<some computed text>";
row.Cells.Add(cell);
tbl.Rows.Add(row);
tbl.Visible = true;
Jul 21 '05 #1
3 1355
Hi G-Fit,

First of all, I would like to confirm my understanding of your issue. From
your description, I understand that you need to add rows to a Table control
each time a button is clicked. If there is any misunderstanding, please
feel free to let me know.

As far as I know, this cannot be achieved automatically by viewstate. The
newly added rows were not written to viewstate, so each time you click a
button, it will only show the row with the latest added values.

For workaround, we have to add the rows in Page_Load event handler. Each
time the button is clicked, we add the row values to an array, and save the
array in viewstate manually. When the page is loaded, we get the array from
the viewstate and add rows to the Table.

HTH.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

Jul 21 '05 #2
"Kevin Yu [MSFT]" <v-****@online.microsoft.com> a écrit dans le message de
news:13****************@cpmsftngxa06.phx.gbl...
Hi G-Fit,

First of all, I would like to confirm my understanding of your issue. From
your description, I understand that you need to add rows to a Table control each time a button is clicked. If there is any misunderstanding, please
feel free to let me know.
You got it right.
As far as I know, this cannot be achieved automatically by viewstate. The
newly added rows were not written to viewstate, so each time you click a
button, it will only show the row with the latest added values.

For workaround, we have to add the rows in Page_Load event handler. Each
time the button is clicked, we add the row values to an array, and save the array in viewstate manually. When the page is loaded, we get the array from the viewstate and add rows to the Table.


OK. I do not know how to manually save something in the viewstate, so
instead I saved my ArrayLists in Session variables. It works, but if saving
in the viewstate is better, I'd like to know.
Jul 21 '05 #3
Hi G-Fit,

Saving to ViewState is the same as saving to Session. Use
ViewState["arrayListName"] = arrayList; to save the arraylist to ViewState.
Since ViewState is put in the page, saving the object to ViewState will
consume less resource on the server than Session.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

Jul 21 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: John Kirksey | last post by:
I have a page that uses an in-place editable DataGrid that supports sorting and paging. EnableViewState is turned ON. At the top of the page are several search fields that allow the user to filter...
3
by: Steve Drake | last post by:
All, I have a CONTROL that contains 1 control (Control ONE), the 1 control that it can contain 1 or 2 control (Control A and B). Control A, raises and event and Control ONE receives this event...
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...
1
by: Simon | last post by:
Hi everyone, I have a quick question that I hope someone can help me with: I've made a user control that contains a text box and some validation functionality. This control has a few extra...
7
by: et | last post by:
I'm not sure I understand the use of the ViewState. Do I understand correctly that values of controls are automatically held in a hidden control called ViewState? If so, then why can't we get...
3
by: RCS | last post by:
I have an app that I have different "sections" that I want to switch back and forth from, all while having the server maintain viewstate for each page. In other words, when I am on Page1.aspx and...
9
by: Mark Broadbent | last post by:
Been a while since I've touched asp.net but one thing that always seems to fustrate me is the loss of state on variable declarations. Is there anyway (i.e. assigning an attribute etc) to instruct...
6
by: hitendra15 | last post by:
Hi I have created web user control which has Repeater control and Linkbutton in ItemTemplate of repeater control, following is the code for this control On first load it runs fine but when...
6
by: paul.hester | last post by:
Hi all, Does anyone know why the ViewState would be empty? When I'm receiving a postback, I can access a posted value using controlName.Value but not ViewState. I have EnableViewState set...
12
by: Nick C | last post by:
Hi How can i reduce the viewstate for my asp.net application. It is getting very large now. What is a good solution? thanks N
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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.