Monday, January 23, 2012

Hidden Fields


You can store page-specific information in a hidden field on your page as a way of maintaining the state of your page.

ASP.NET allows you to store information in a HiddenField control, which renders as a standard HTML hidden field. A hidden field does not 

render visibly in the browser, but you can set its properties just as you can with a standard control. When a page is submitted to the server, 

the content of a hidden field is sent in the HTTP form collection along with the values of other controls. A hidden field acts as a repository for 

any page-specific information that you want to store directly in the page.


HTML code:
<input type="hidden" name="HTMLHiddenField" id="HTMLHiddenField" value="" />

C# Code
string message = Request.Form["HTMLHiddenField"];


Advantages of Hidden Fields:
1: No server resources are required. The hidden field is stored and read from the page.
2: Widespread support. Almost all browsers and client devices support forms with hidden fields.
3: Simple implementation. Hidden fields are standard HTML controls that require no complex programming logic.

Disadvantages of Hidden Fields:
1: Potential security risks. The hidden field can be tampered with. The information in the hidden field can be seen if the page output source is 

viewed directly, creating a potential security issue. 
2: Simple storage architecture. The hidden field does not support rich data types.

No comments: