Wrox Programmer Forums
|
BOOK: Beginning ASP.NET 4.5 : in C# and VB
This is the forum to discuss the Wrox book Beginning ASP.NET 4.5: in C# and VB by Imar Spaanjaars; ISBN: 978-1-118-31180-6
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning ASP.NET 4.5 : 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 April 17th, 2014, 01:29 AM
Registered User
 
Join Date: Apr 2014
Posts: 1
Thanks: 1
Thanked 0 Times in 0 Posts
Default ViewState property

In chapter 8 in the try it out exercise on implementing View state Properties we create a banner in the AboutUs.aspx page on top of the banner that is in the master page.

During the execution of the first AboutUs.aspx call where the NavigateUrl is set to p2p.wrox.com as below:

Code:
 public string NavigateUrl 
    {
      get
      {
        object _navigateUrl = ViewState["NavigateUrl"];
        if (_navigateUrl != null)
        {
          return (string)_navigateUrl;
        }
        
        return "http://p2p.wrox.com";
      }
      set
      {
        ViewState["NavigateUrl"] = value;
      }
    }
This portion makes sense.

However, during the

Code:
protected void Page_Load(object sender, EventArgs e)
    {
      switch (DisplayDirection)
      { 
        case Direction.Horizontal:
          HorizontalPanel.Visible = true;
          VerticalPanel.Visible = false;
          HorizontalLink.HRef = NavigateUrl;
          break;
        case Direction.Vertical:
          HorizontalPanel.Visible = false;
          VerticalPanel.Visible = true;
          VerticalLink.HRef = NavigateUrl;
          break;
      }
    }
The switch statement is executed twice (I think 1 for each banner control) and the correct viewstate property is retrieved. The master page banner has a link to www.wrox.com and the additional banner in aboutUs to p2p.wrox.com.

Does this mean that view state property is maintained for each control? If so, then I am curious to know what is the scope of the view state prop, meaning does each and every control have a viewstate property and what does not have?

Thanks in advance.

To Imaar... This book rocks. for a beginner like me, I love it.
 
Old April 18th, 2014, 03:38 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,

Yes, that's correct. Every control has a ViewState property: http://msdn.microsoft.com/en-us/libr...vs.110%29.aspx) This in turn means that all controls that inherit from it (including the Page class) have this property as well. Internally, ASP.NET keeps track of the data in ViewState per control so after a postback it's able to relate the data in ViewState back to the original control.

>> To Imaar... This book rocks. for a beginner like me, I love it.

Good to hear. Thanks!

Hope this helps,

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:
decryptMe (April 24th, 2014)





Similar Threads
Thread Thread Starter Forum Replies Last Post
chp 01, get[property name] and set[property name] sandeepgreaternoida BOOK: Professional PHP 5 ISBN: 978-0-7645-7282-1 0 May 12th, 2009 01:12 AM
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.