473,406 Members | 2,698 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,406 software developers and data experts.

EnableViewState not working on table

AFN
I have a server-side table,

<asp:table id="tblData" EnableViewState="true" runat="server" />

and my code-behind adds rows of data to the table in code that says:

if not page.ispostback then
LoadDataTable()
end if

I also have a checkbox, with autopostback=true.

On the first page_load, the data table has rows of data. The problem is
that when I check the checkbox and the page posts back, the table
disappears. I don't understand why it doesn't preserve the table
considering EnableViewState is true?????
Nov 19 '05 #1
6 4661
Try reloading the LoadDataTable() on postback.
I dont think viewstate will work for Table.
It is also similar behaviour when you create the controls dynamically.
Need to reload them on postback.

"AFN" wrote:
I have a server-side table,

<asp:table id="tblData" EnableViewState="true" runat="server" />

and my code-behind adds rows of data to the table in code that says:

if not page.ispostback then
LoadDataTable()
end if

I also have a checkbox, with autopostback=true.

On the first page_load, the data table has rows of data. The problem is
that when I check the checkbox and the page posts back, the table
disappears. I don't understand why it doesn't preserve the table
considering EnableViewState is true?????

Nov 19 '05 #2
AFN
I know that reloading the table data will work, but that's so wasteful.
The table element shows EnableViewState in its properties in the designer,
so I don't see why it wouldn't work.
"vinay" <vi***@discussions.microsoft.com> wrote in message
news:0B**********************************@microsof t.com...
Try reloading the LoadDataTable() on postback.
I dont think viewstate will work for Table.
It is also similar behaviour when you create the controls dynamically.
Need to reload them on postback.

"AFN" wrote:
I have a server-side table,

<asp:table id="tblData" EnableViewState="true" runat="server" />

and my code-behind adds rows of data to the table in code that says:

if not page.ispostback then
LoadDataTable()
end if

I also have a checkbox, with autopostback=true.

On the first page_load, the data table has rows of data. The problem is that when I check the checkbox and the page posts back, the table
disappears. I don't understand why it doesn't preserve the table
considering EnableViewState is true?????

Nov 19 '05 #3
The Table's Viewstate maintains property changes on the table control (e.g.
Width, Height).
The problem is that the rows/cells you're adding are different controls.
The table would not keep track of those other controls (think of it as a
panel that you're dynamically adding textboxes to).
"AFN" <ne***************************@DELETETHISyahoo.com > wrote in message
news:8B*******************@twister.socal.rr.com...
I have a server-side table,

<asp:table id="tblData" EnableViewState="true" runat="server" />

and my code-behind adds rows of data to the table in code that says:

if not page.ispostback then
LoadDataTable()
end if

I also have a checkbox, with autopostback=true.

On the first page_load, the data table has rows of data. The problem is
that when I check the checkbox and the page posts back, the table
disappears. I don't understand why it doesn't preserve the table
considering EnableViewState is true?????

Nov 19 '05 #4
AFN
Good point, but now what? All I'm doing is adding rows and cells. How can
I make those part of the viewstate? I really don't want to call the
database twice. I actually do about 4 database calls to produce the data
and it would be a huge waste to do that again. Maybe caching will work (I
don't know if caching will work on postback caused by the checkbox being
checked, which triggers the server-side exposing of a panel that is
otherwise invisible), but I'd prefer to just put the table rows/cells in
viewstate.
"David Jessee" <dj*****@houston.rr.com> wrote in message
news:ec****************@TK2MSFTNGP10.phx.gbl...
The Table's Viewstate maintains property changes on the table control (e.g. Width, Height).
The problem is that the rows/cells you're adding are different controls.
The table would not keep track of those other controls (think of it as a
panel that you're dynamically adding textboxes to).
"AFN" <ne***************************@DELETETHISyahoo.com > wrote in message
news:8B*******************@twister.socal.rr.com...
I have a server-side table,

<asp:table id="tblData" EnableViewState="true" runat="server" />

and my code-behind adds rows of data to the table in code that says:

if not page.ispostback then
LoadDataTable()
end if

I also have a checkbox, with autopostback=true.

On the first page_load, the data table has rows of data. The problem is that when I check the checkbox and the page posts back, the table
disappears. I don't understand why it doesn't preserve the table
considering EnableViewState is true?????


Nov 19 '05 #5
You can't. Controls are not serializable so they can't be asses to the
viewstate.
Save whatever information you need to in the viewstate, then rebuild the
table during the page's Init event.

as far as the database calle that get the data for the table
construction...create a class that represents the data you need. Remember
that you can have properties that are arraylists so whatever you need to
store in that class, you can store. Make sure that the class is marked as
serializable, then save THAT in your viewstate. (Even better yet, instead
of putting all of that logic in your page, make your Data Access Class
return that class)

<Serializable()> Public Class TableStructureDescriptor
....your implementation
End Class

then in your aspx code behind......

Public Class MyPage
Inherits Page

Private Const vs_theStructure as string = "TableStructure"

Public Property TableStructure as TableStructureDescriptor
Get
if Viewstate(vs_theStructure) is nothing then return nothing
return
CType(Viewstate(vs_theStructure),TableStructureDes criptor)
End Get
Set(Value as TableStructureDescriptor)
Viewstate(vs_theStructure)=Value
End Set
End Property

Private Page_Init()
If Not TableStructure is nothing then
BuildTable()
End if
End Sub

End Class
End Class

"AFN" <ne***************************@DELETETHISyahoo.com > wrote in message
news:16*******************@twister.socal.rr.com...
Good point, but now what? All I'm doing is adding rows and cells. How can I make those part of the viewstate? I really don't want to call the
database twice. I actually do about 4 database calls to produce the data
and it would be a huge waste to do that again. Maybe caching will work (I
don't know if caching will work on postback caused by the checkbox being
checked, which triggers the server-side exposing of a panel that is
otherwise invisible), but I'd prefer to just put the table rows/cells in
viewstate.
"David Jessee" <dj*****@houston.rr.com> wrote in message
news:ec****************@TK2MSFTNGP10.phx.gbl...
The Table's Viewstate maintains property changes on the table control

(e.g.
Width, Height).
The problem is that the rows/cells you're adding are different controls.
The table would not keep track of those other controls (think of it as a
panel that you're dynamically adding textboxes to).
"AFN" <ne***************************@DELETETHISyahoo.com > wrote in message
news:8B*******************@twister.socal.rr.com...
I have a server-side table,

<asp:table id="tblData" EnableViewState="true" runat="server" />

and my code-behind adds rows of data to the table in code that says:

if not page.ispostback then
LoadDataTable()
end if

I also have a checkbox, with autopostback=true.

On the first page_load, the data table has rows of data. The problem

is that when I check the checkbox and the page posts back, the table
disappears. I don't understand why it doesn't preserve the table
considering EnableViewState is true?????



Nov 19 '05 #6
AFN
Thanks for all the helpful sample code and idea.
"David Jessee" <dj*****@houston.rr.com> wrote in message
news:uA****************@tk2msftngp13.phx.gbl...
You can't. Controls are not serializable so they can't be asses to the
viewstate.
Save whatever information you need to in the viewstate, then rebuild the
table during the page's Init event.

as far as the database calle that get the data for the table
construction...create a class that represents the data you need. Remember
that you can have properties that are arraylists so whatever you need to
store in that class, you can store. Make sure that the class is marked as
serializable, then save THAT in your viewstate. (Even better yet, instead
of putting all of that logic in your page, make your Data Access Class
return that class)

<Serializable()> Public Class TableStructureDescriptor
...your implementation
End Class

then in your aspx code behind......

Public Class MyPage
Inherits Page

Private Const vs_theStructure as string = "TableStructure"

Public Property TableStructure as TableStructureDescriptor
Get
if Viewstate(vs_theStructure) is nothing then return nothing
return
CType(Viewstate(vs_theStructure),TableStructureDes criptor)
End Get
Set(Value as TableStructureDescriptor)
Viewstate(vs_theStructure)=Value
End Set
End Property

Private Page_Init()
If Not TableStructure is nothing then
BuildTable()
End if
End Sub

End Class
End Class

"AFN" <ne***************************@DELETETHISyahoo.com > wrote in message
news:16*******************@twister.socal.rr.com...
Good point, but now what? All I'm doing is adding rows and cells. How

can
I make those part of the viewstate? I really don't want to call the
database twice. I actually do about 4 database calls to produce the data
and it would be a huge waste to do that again. Maybe caching will work (I don't know if caching will work on postback caused by the checkbox being
checked, which triggers the server-side exposing of a panel that is
otherwise invisible), but I'd prefer to just put the table rows/cells in
viewstate.
"David Jessee" <dj*****@houston.rr.com> wrote in message
news:ec****************@TK2MSFTNGP10.phx.gbl...
The Table's Viewstate maintains property changes on the table control

(e.g.
Width, Height).
The problem is that the rows/cells you're adding are different controls. The table would not keep track of those other controls (think of it as a panel that you're dynamically adding textboxes to).
"AFN" <ne***************************@DELETETHISyahoo.com > wrote in message news:8B*******************@twister.socal.rr.com...
> I have a server-side table,
>
> <asp:table id="tblData" EnableViewState="true" runat="server" />
>
> and my code-behind adds rows of data to the table in code that says:
>
> if not page.ispostback then
> LoadDataTable()
> end if
>
> I also have a checkbox, with autopostback=true.
>
> On the first page_load, the data table has rows of data. The

problem is
> that when I check the checkbox and the page posts back, the table
> disappears. I don't understand why it doesn't preserve the table
> considering EnableViewState is true?????
>
>



Nov 19 '05 #7

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

Similar topics

0
by: Dave Verwer | last post by:
Hi I have a problem which is easily reproducable using VS.NET 2003 and the .Net framework 1.1 (not tested with framework 1.0) regarding disabling ViewState for dynamically created controls. ...
1
by: Mike D | last post by:
This is becoming very painful to learn. I am going through a wrox book and trying the code. My aspx pages continue to come back with my selection highlighted. It looks like EnableViewState is...
7
by: Max Metral | last post by:
I have a Web.config in my application root dir with the following pages directive: <pages buffer="true" enableViewState="false" enableSessionState="false" enableViewStateMac="false"/> And...
4
by: Bruce Chao | last post by:
I tried to turn off viewstate and so I added enableViewState=false in side the Page directive, rebuild the page, test it. - not working Then I set all controls on the page so all their...
7
by: Brian Henry | last post by:
Hi, I want EnableViewState = false turned on to optimize the end output page (it was over 600KB with it on) but when i turn it off, our pageing functionality no longer works mainly the...
3
by: Paul W | last post by:
I have a ListBox Webcontrol with an OnSelectedIndexChanged event (and AutoPostBack=true). If I disable EnableViewState for this control, when I change the listbox index, the form does a postback...
1
by: AC | last post by:
Hello, All Is it possible to set enableViewState='true' for single control on a page with enableViewState='false'. In particular I am interested in DropDownList, but neither using IDE to set...
7
by: Just D. | last post by:
Does anybody know any good solution to avoid this setting to be enabled? I guess Microsoft doesn't care of the Internet connection of the potential client working with asp.net. This EnableViewState...
1
by: Jonathan Wood | last post by:
I have a table that I dynamically populate by creating cells and rows. The data comes from a database so I would prefer to have the table store the data in its viewstate rather than having to...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.