asp.net 2.0 new Controls-hiddenfield

Source: Internet
Author: User
Asp.net| Control

The HiddenField control, as its name implies, is a server control that hides the input box, allowing you to save data that is not required to be displayed on the page and that is less secure. Perhaps this time should have such a question, why have viewstate, session and cookies and other state preservation mechanism, still need to "return to old age" use HiddenField? To increase the HiddenField, in fact, to make the whole state management mechanism more comprehensive application. Because whether ViewState, session, or cookie has its expiration time (for example, the user set ViewState to False for some requirement, or the environment condition restricts using session or cookie, etc.), At this time HiddenField is undoubtedly the best choice, also shows that the simple and practical things will never expire the truth.

In this regard, Lenovo to the previous BulletedList control of the reasons, unexpectedly there are similarities. I think, although they are "obscure" control, but their recurrence brings us more thinking and meaning than their technical applications bring us much more. Throw away the glasses that "underestimate" anything, and you will find it worth boasting.

The primary members of the HiddenField control have the Value property and the ValueChanged event:

L Value: The value in the hidden input box is guaranteed.

L ValueChanged: Triggers the event when the value changes. However, in my debugging process, I found that the HiddenField control should also be set to the EnableViewState property to False, the default is true in case the value value does not change, so that the event cannot be triggered.

Simple example: Default.aspx

<%@ Page language= "C #"%>

<! DOCTYPE HTML PUBLIC "-//w3c//dtd XHTML 1.1//en" "Http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd" >

<script runat= "Server" >

protected void Page_Load (object sender, EventArgs e)

{

if (Hiddenfield1.value = = String.Empty)

Hiddenfield1.value = "0";

}

protected void Button1_Click (object sender, EventArgs e)

{

Hiddenfield1.value = (Convert.ToInt32 (hiddenfield1.value) + 1). ToString ();

Label1.Text = Hiddenfield1.value;

}

protected void Hiddenfield1_valuechanged (object sender, EventArgs e)

{

Response.Write ("Changed." + DateTime.Now.ToString ());

}

</script>

<title>untitled page</title>

<body>

<form id= "Form1" runat= "Server" >

<div>

<asp:hiddenfield id= "HiddenField1" runat= "onvaluechanged=" hiddenfield1_valuechanged "enableviewstate=" False "/>

</div>

<asp:label id= "Label1" runat= "Server" text= "Label" ></asp:Label>

<br/>

<asp:button id= "Button1" runat= "Server" text= "button"/>

</form>

</body>

[summary]: As mentioned earlier, although HiddenField is a "humble" control, but its recurrence brings us more thinking and significance than its technical application to bring us much more.

[Resources]:

1. MSDN Library for Visual Studio Beta2

2. http://beta.asp.net/QUICKSTART/aspnet/default.aspx



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.