473,320 Members | 1,600 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,320 software developers and data experts.

page viewstate

How come I can use the following line in my page_load
ViewState["abc123"] = "xxxx"

But when I try the same line of code in another function I get the following compile error
An object reference is required for the nonstatic field, method, or property 'System.Web.UI.Control.ViewState

Do I need to reference ViewState some how thru the HttpContext.current ???

Nov 18 '05 #1
3 2302
When you access it through Page_Load it is intrinsically available. Can you
send an example of the code where ViewState is not available?

"jzink" <an*******@discussions.microsoft.com> wrote in message
news:97**********************************@microsof t.com...
How come I can use the following line in my page_load:
ViewState["abc123"] = "xxxx";

But when I try the same line of code in another function I get the following compile error: An object reference is required for the nonstatic field, method, or property 'System.Web.UI.Control.ViewState'
Do I need to reference ViewState some how thru the HttpContext.current ????

Nov 18 '05 #2
Do you mean another function or another class? The Page class inherits
System.Web.UI.Control. The ViewState property is a property of the base
class, so in any class that inherits System.Web.UI.Control has a ViewState
property. If you're referring to a method in a non-Control class, such as a
Class Library, you would have to get the ViewState from the
System.Web.HttpContext.Current.Handler class. This class is an iHttpHandler
class, so you would need to cast it as a System.Web.UI.Page class. Example:

((System.Web.UI.Page)
System.Web.HttpContext.Current.Handler).ViewState["abc123"] = "xxxx";

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.

"jzink" <an*******@discussions.microsoft.com> wrote in message
news:97**********************************@microsof t.com...
How come I can use the following line in my page_load:
ViewState["abc123"] = "xxxx";

But when I try the same line of code in another function I get the following compile error: An object reference is required for the nonstatic field, method, or property 'System.Web.UI.Control.ViewState'
Do I need to reference ViewState some how thru the HttpContext.current ????

Nov 18 '05 #3
I was hoping to do exactly as you describe (i.e., access the ViewState
from a class), however, when I implement the code you suggest, I get the
following compile-time error:

'System.Web.UI.Control.ViewState' is
inaccessible due to its protection level

Could you kindly provide an explanation for how to get around that? Many
thanks in advance.
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 18 '05 #4

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

Similar topics

3
by: Stephen | last post by:
I was wondering if someone can help me with an web application design problem. I have a aspx page which builds up an arraylist called addresses and outputs the values in the arraylist items to a...
2
by: Mike | last post by:
hi to all does any body know or receive this message before and how i can repare this: The viewstate is invalid for this page and might be corrupted. thank's Mike
4
by: Kevin Phifer | last post by:
Ok, before anyone freaks out, I have a solution I need to create that gathers content from maybe different places. Each one can return a <form> in the html, so its the classic can't have more than...
1
by: AMD Desktop | last post by:
Hi, I have a problem and not sure what is going on here, may be the coding is not proper. This is a simple page with calendar events. Everything works fine until I click on View Week link. Then...
0
by: seven | last post by:
I have a base page with an HTMLForm object (added to the base page control heiarchy during Init). In the design of pages derived from this base page, I can choose to create controls and add them...
5
by: tshad | last post by:
Is there a way to carry data that I have already read from the datagrid from page to page? I am looking at my Datagrid that I page through and when the user says get the next page, I have to go...
1
by: Petr SIMUNEK | last post by:
I have 3 buttons on the page. (Created dynamicaly inside For- next loop and hooked up to click event.) When different button is clicked i would like to save a different value to viewstate. In the...
5
by: Frank | last post by:
I'm really stumped here. I have a couple pages where I'm using a datagrid and a custom paging solution. I store the current page, sort column, etc in the ViewState of the page. When a column is...
9
by: Alexander van Doormalen | last post by:
I have a situation that user controls are dynamically loaded within a page. To know which control to 're-add' to the page I saved the control path in the ViewState. This Control is added using...
4
by: Dan | last post by:
Hi, i'm not sure to understand the difference between refreshing the pagina by clicking on 'refresh' in the browser and a postback. What i think it is: Suppose a page with a form containing a...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.