Asp. NET, HiddenField the use of hidden controls

Source: Internet
Author: User

The HiddenField control is a server control that hides the input box, allowing you to save data that doesn't need to be displayed on the page and is not very secure. Perhaps this time should have such a question, why have viewstate, session and cookie State preservation mechanism, still need to use HiddenField?


The increase of HiddenField is in order to make the whole state management mechanism more fully applied. Because whether it is viewstate, cookie or session, has its expiration time, such as the user because of a certain demand set ViewState to false, or environmental conditions limit the use of cookies, or the user for a long time no action causes the session expires and so on, At this time HiddenField is undoubtedly the best choice.

You can generally use it for sorting options:

such as front code:

<webdiyer:aspnetpager id= "AspNetPager1"  runat= "Server"  width= "100%"  showpageindexbox= " Always "         pageindexboxtype=" DropDownList "  Textbeforepageindexbox= "Go to:"  horizontalalign= "Center"          Pagesize= " alwaysshow=" True " onpagechanged=" aspnetpager1pagechanged "         cssclass= "pagination"  currentpagebuttonclass= "active"           showcustominfosection= "Right"          Custominfohtml= "Current page%currentpageindex%/%pagecount%   Total%recordcount% records  %pagesize% per page" ></webdiyer : aspnetpager>        <asp:hiddenfield runat= "Server"   Id= "SortType"/>        <asp:hiddenfield runat= "Server"  id= "SortField"/>

part of the code that loads the data in the background:

Private void loaddata ()         {             int count;             int pagesize = AspNetPager1.PageSize;             var pageIndex = AspNetPager1.CurrentPageIndex;             string order =  " CreatedOn ";             //sort Selection              if  (!string. IsNullOrEmpty (Sortfield.value))//sortfield for hidden controls              {                 order = sortfield.value;            }            if  (sorttype.value ==  "ASC")//sortorder as a hidden control, positive order              {                 _sortOrder = SortOrder.Ascending;             }            var list =  _chemicaladapter.fetchchemicals (_name.text,_number.text,null, pageindex,                 pagesize, order, _sortorder,  out count);             aspnetpager1.recordcount = count;             _projectgrid.datasource =&nbSp;list;            _projectgrid.databind ();         }


This article is from "Uncle Wei Xiaobao" blog, please be sure to keep this source http://darmi.blog.51cto.com/11607923/1786847

Asp. NET, HiddenField the use of hidden controls

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.