Wrox Programmer Forums
|
BOOK: Beginning ASP.NET 4 : in C# and VB
This is the forum to discuss the Wrox book Beginning ASP.NET 4: in C# and VB by Imar Spaanjaars; ISBN: 9780470502211
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning ASP.NET 4 : in C# and VB section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 28th, 2010, 06:43 PM
Registered User
 
Join Date: Jun 2010
Posts: 9
Thanks: 2
Thanked 0 Times in 0 Posts
Default chapter8-viewstate collection

Hi all!
I understood from reading so far, that the hidden viewstate string, saves the state of server controls across postbacks.
Now, a user control is written in the markup view, as it was a normal control from the toolbox, but the book says taht it can be considered as an aspx page since it has it's own controls and properties etc.

In the web site gradually built by the book, there is the aboutus.aspx page.
It renders 2 banners, one from the master page and one from the page itself.
I dont understand if the viewstate string of aboutus.aspx applies to the usercontrols as well, or that the usercontrols have their own viewstate strings, since they are considered as aspx pages as written above.

I'm only asking this because when aboutus.aspx page is constructed at the server after user requested it, the following code is fired:
Code:
 Banner2.NavigateUrl = "http://imar.spaanjaars.com";
and on the following postbacks in this same aboutus.aspx page, it seems that the "viewstate update" by this line of code, applies only to the Banner2 user control and not to the viewstate string of the aboutus.aspx page.


10x ppl for at least getting here in reading...

Last edited by lustigon; June 28th, 2010 at 06:46 PM..
 
Old June 29th, 2010, 02:14 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi there,

The whole page makes use of the same hidden ViewState field. It works in a hierarchical way. E.g:
Code:
 
 
AboutUs.aspx
  SomeButton
  SomeTextBox
  BannerUser Control
    SomeButton
    SomeLinkButton
    HyperLinkForLink control
    SomeOther control
All these controls all make use of the same hidden ViewState field defined in AboutUss.aspx

Does that help?

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
 
Old June 29th, 2010, 06:17 AM
Registered User
 
Join Date: Jun 2010
Posts: 9
Thanks: 2
Thanked 0 Times in 0 Posts
Default

Hi Imar.
It sure helps.
what really confused me was that when aboutus.aspx is requested, 2 Banner user controls should be populated, and both get the HREF value from the getter of the NavigateUrl property(belongs to the usercontrol).
Now, when this code fires:
Code:
Banner2.NavigateUrl = "http://imar.spaanjaars.com";
the viewstate string of the entire page is updated(according to your reply), so when the Banner1 user control(located in the masterpage) is populated it also uses the getter of the NavigateUrl property, that seeks in the viewstate collection for the value that the above line of code entered, but!it does not find it, so it gets the HREF value of the p2p.wrox.com....
When the Banner2 usercontrol(located in aboutus.aspx) is populated, again it uses the same getter, but this time it finds the value in the viewstate collection, and the HREF value is:http://imarsp....

That is why i thought that usercontrols have viewstate fields of their own.
I guess the runtime knows how to differentiate between the 2 usercontrols due to the hierarchical way of working as you mentioned.
do i get it right? or maybe I'm digging to deep into it with no practical reason?

10x,
 
Old June 29th, 2010, 06:45 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Quote:
That is why i thought that usercontrols have viewstate fields of their own.
They do, more or less, but store it in the same page-scoped ViewState field, see below
Quote:
I guess the runtime knows how to differentiate between the 2 usercontrols due to the hierarchical way of working as you mentioned.
Exactly. That's why it's so important that two controls on the same page can't share the same ID unless they are in a unique naming container (e.g. the link controls have the same ID but their Banner parent is different. Thus the "path" to the link is unique: Banner1.HyperLink1 and Banner2.HyperLink1 for example.
Quote:
do i get it right? or maybe I'm digging to deep into it with no practical reason?
Yes, you do get it right. And I don't think you're digging too deep. The better you understand this, the easier it is to make use of it.

Cheers,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
The Following User Says Thank You to Imar For This Useful Post:
lustigon (June 29th, 2010)





Similar Threads
Thread Thread Starter Forum Replies Last Post
ViewState Wervis C# 1 December 3rd, 2005 11:35 AM
Viewstate Wervis BOOK: ASP.NET Website Programming Problem-Design-Solution 0 November 30th, 2005 09:42 AM
ViewState abdul_owiusa General .NET 0 October 18th, 2005 04:37 PM
ViewState burhan ASP.NET 1.0 and 1.1 Basics 4 June 6th, 2004 04:25 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.