DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
View Events Video Library
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Integrating PostgreSQL Databases with ANF: Join this workshop to learn how to create a PostgreSQL server using Instaclustr’s managed service

[DZone Research] Observability + Performance: We want to hear your experience and insights. Join us for our annual survey (enter to win $$).

Monitoring and Observability for LLMs: Datadog and Google Cloud discuss how to achieve optimal AI model performance.

Automated Testing: The latest on architecture, TDD, and the benefits of AI and low-code tools.

Related

  • Empowering Real-World Solutions the Synergy of AI and .NET
  • Why Angular and ASP.NET Core Make a Winning Team
  • Role of C# in Building Dynamic and Secure Web Applications
  • PHP or ASP.NET: Which Powerhouse Platform Prevails for Your Next Project?

Trending

  • Embracing Reactive Programming With Spring WebFlux
  • Programming With AI
  • Modern Data Backup Strategies for Safeguarding Your Information
  • Driving Digital Transformation Through the Cloud
  1. DZone
  2. Coding
  3. Frameworks
  4. ASP.NET - Client Side State Management - Control State

ASP.NET - Client Side State Management - Control State

Gil Fink user avatar by
Gil Fink
·
Jul. 31, 08 · News
Like (1)
Save
Tweet
Share
39.28K Views

Join the DZone community and get the full member experience.

Join For Free

In this post I'm going to explain what is the control state and how to use it as a part of the ASP.NET client side state management. You can read my previous posts in the state management subject in the following links:

  • Client side state management introduction
  • ViewState technique
  • Hidden fields technique
  • Query strings technique
  • Cookies technique


What is Control State?

The control state is a way to save a control’s state information when the EnableViewState property is turned off. Unlike ViewState a developer can’t turn off control state. The control state can be implemented only in controls that you implement.

How to Use Control State?

Control state implementation is easy. First, override the OnInit method of the control and add the call for the Page.RegisterRequiresControlState method with the instance of the control to register. Then, override the  LoadControlState and SaveControlState in order to save the required state information.

The next example shows a simple implementation for a control that saves a string as a state information:

public class ControlStateWebControl : Control{#region Membersprivate string _strStateToSave;#endregion#region Methodsprotected override void OnInit(EventArgs e){    Page.RegisterRequiresControlState(this);    base.OnInit(e);}protected override object SaveControlState(){    return _strStateToSave;}protected override void LoadControlState(object state){    if (state != null)    {_strStateToSave = state.ToString();    }}#endregion}

 

You need to remember only one thing – the control state takes away the choice to disable ViewState. You should
only use it whenever you have to keep a state information that without it your control won’t work. 

Summary

To sum up the post, I showed what is the control state and how to enable it in your controls. The control state takes away the decision of a developer whether to use ViewState or not. Whenever you want to use the control state you should think whether to implement it or give the decision of how to save the state information to the developers that use your control. I prefer the second choice. In the next post in this series I’ll start to explain the server side state
management.

ASP.NET

Opinions expressed by DZone contributors are their own.

Related

  • Empowering Real-World Solutions the Synergy of AI and .NET
  • Why Angular and ASP.NET Core Make a Winning Team
  • Role of C# in Building Dynamic and Secure Web Applications
  • PHP or ASP.NET: Which Powerhouse Platform Prevails for Your Next Project?

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends: