Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Viewstate - is it what I need?

Status
Not open for further replies.

phbrady

Programmer
Oct 17, 2003
41
US
I am trying to pass values between pages. I have a large table I am building dynamically to display my data. The table contains and ItemNumber Textbox and an ItemID textbox with visible set to false.

Problem #1 is, I want to populate the ItemID Textbox from a popup window where the user chooses a value, but since the TextBox is not visible, this doesn't work.

Problem #2 is, how do I retrieve the value of the ItemID textbox on a postback? When I try to access the page's viewstate (Page.ViewState), I get the following error:
---------------
Compiler Error Message: BC30390: 'System.Web.UI.Control.Protected Overridable ReadOnly Property ViewState() As System.Web.UI.StateBag' is not accessible in this context because it is 'Protected'
---------------
What does this error mean in this context and what can I do about it? Can I not access the viewstate info?

What's the most efficient way to pass a large number of values between postbacks? If anyone could provide specific examples, that would be a huge help as I am moving from and ASP to an ASP.Net environment.

Thanks!!
 
OK - I am a little confused, but maybe this can help

1. Unfortunately, I've had some experience with trying to make dynamically constructed tables persist between postbacks. Bottom line - they don't. It will get rendered, but all it's contents will not be available to code in a postback. Datagrids, however, do, as long as you turn on enableViewState. But the problem then is that it is more difficult to dynamically construct a datagrid. I worked around by artificially creating a data table for the dg to bind to.

2. I'm not 100% clear from your question whether you want to access the information in the same page or in a different page. If in the same page, then all the values of controls should just be available, as long as you've turned on enableViewState for them. It is not necessary to explicitly use ViewState - you'd only be duplicating information already in there.

3. If you want to access the values in a different page, you have a choice of three methods.

3a. Session Variables.
3b. The QueryString (which you have to construct manually, but which you can query easily). This only works with a response.redirect transfer, I think.
3c. 3a works no matter how you transfer from one page to the other. However, if you are happy to use the server.transfer, rather than the response.redirect method, you have a third choice. You can just get the values directly, since the calling webform is still in memory. I cannot remember exactly the syntax for doing this, but a search for server.transfer in the help will give some example code.

Oh - as for problem 1 - I presume you are using client side script for the popup window thing? If so, remember that if you set the .visible property of something to false in asp.net, it does not even get rendered. If you want it to be simply hidden from view, either use "display:none" as it's style, or use an input HTML control of type hidden.

Hope this helps

Mark [openup]
 
Thanks. I think I'm going to try a different approach altogether.

P
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top