1 / 4
2 / 4
3 / 4
4 / 4

Friday, 3 January 2020

Client-side State Management(Hidden Field).Part-2


In client-side state management, the state of value is maintained(Stored) on the client machine for further use.

       1.  Hidden Field          2. Query String
       3.  View State             4.   Cookies

Hidden Field

Using Hidden Field we can maintain the value between the roundtrip.

1.      Hidden Field is an ASP Control.

 
            <asp: HiddenField ID=”HiddenField1” value=”0” runat=”server” />
2.      Hidden Field is invisible to the end-user.
3.      It stores the value in String format.


Example:-
>> In StateManagementDemo2.aspx

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
        <div><asp:HiddenField ID="hdfCount" Value="0" runat="server" />
            <asp:Button ID="btnClick" Text="Click Me" OnClick="btnClick_Click" runat="server"/>
            <asp:Button ID="btnGo" Text="Go" PostBackUrl="~/RedirectedForm.aspx" runat="server" />
        </div>
    </form>
</body>
</html>


>> In StateManagementDemo2.aspx.cs

using System;
namespace MyPalmBookWeb
{
    public partial class StatemanagementDemo2 : System.Web.UI.Page
    {
        int i = 0;
        protected void Page_Load(object sender, EventArgs e)
        {   
        }
        protected void btnClick_Click(object sender, EventArgs e)
        {
           // i +=1;
            i = int.Parse(hdfCount.Value) + 1;
            Response.Write(i);
            hdfCount.Value = i.ToString();
        }
    }
}



>> In RedirectedForm.aspx.cs

using System;
namespace MyPalmBookWeb
{
    public partial class RedirectedForm : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            string hdfval = Request.Form["hdfCount"];
            Response.Write("You have clicked the button :"+hdfval +"times");
        }
    }
}


Watch the video tutorial here

For Query string Click here.


No comments:

Post a Comment

If you have any doubts please let me know