Monday, December 19, 2011

Hidden Field in asp.net

Client Side State Management
(Hidden Field,QueryString,ViewState,Control State,Cookies)

For Cookies:           Click to View Example


For ViewState:       Click to View Example


For QueryString:     Click to View Example


For Control State:   Click to View Example


Hidden Fields:


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.


Example


in .aspx page





<div>
                <h2
                style="color:Green">HiddenField 
                in ASP.NET 4 , C#</h2>
                <asp:HiddenField
                ID="hiddenField"
                runat="server"
                />
                <br
                />
                <asp:Button
                ID="button"
                runat="server"
                Text="Hidden 
                value" 
                onclick="button_Click"
                />
                <br
                />
                <br
                />
                
                       
                
                <asp:Label
                ID="label"
                runat="server"
                Font-Bold="True"
                ForeColor="#000099"
                />
                </div>



in .cs page



 protected
                void 
                Page_Load(object sender, EventArgs  e)
                {
                }
                protected  void button_Click(object sender, EventArgs e)
                {
                if 
                (hiddenField.Value ==  String.Empty)
                hiddenField.Value = "101";
                hiddenField.Value = (Convert.ToInt32(hiddenField.Value) 
                - 1).ToString();
                label.Text = hiddenField.Value;
                }






























No comments:

Post a Comment