I have a hidden filed
<asp:HiddenField ID="hdnCFIV" Value="0" runat="server" />
I am changing the hidden filed value to 1 on a button click
hdnCFIV.Value = "1";
I am binding the datalist on page load
if(hdnCHIV.Value == "1")
But every time hdnCHIV.Value is showing 0 because my ascx page is reloading, if i’ll keep the binding code in side the if(!IsPostBack) then other functionality will get affected.
How to retain the Hidden Field value once it is getting change from 0 to 1 on post back.
Is there any JavaScript or some other way? Please someone help me.
The problem is that Load event occurs earlier than controls’ events are being handled. So current workflow is like this:
hdnCFIV.Valueproperty to 0.Page_Loadis called,hdnCFIV.Valueequals 0 so the datalist binding is not performed.hdnCFIV.Valueis set to 1.To resolve this issue you need to perform datalist binding later, when
hdnCFIV.Valueis already set to 1. You can do this either in the same button click handler or inPage_PreRender.