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