I have the following hidden input field on a aspx page:
<asp:HiddenField ID="MySecretValue" runat="server" />
<asp:Button ID="Submit" runat="server" Text="Save" OnClick="submit_Click" CssClass="btn btn-primary" />
code behind:
protected void Page_Load(object sender, EventArgs e)
{
}
protected void submit_Click(object sender, EventArgs e)
{
// Do some stuff
}
The hidden input is populated via some jQuery script. When the user submits the page I do some stuff inside the submit_Click method and redisplay the page. However when the page redisplays the hidden input field is empty. How do I ensure the hidden field keeps the value when the page is re-displayed?
This code does not lose value after post back ...Try this
Enable
EnableViewState="true"in page directive or web.config.aspx
and .aspx.cs
This link may help you Link