What you are missing here is that with using meta refresh your whole page is being reloaded. The data about checkbox, if it is checked or not, is lost (ViewState is emptied).
What you should do is save the checkbox checked data in some more persistent state, which is kept through reloads, Session object for example.
And then always use the value from the Session instead (of course if the user changes the checkbox value, change the value in Session also).
Example
HTML:
<asp:CheckBox OnCheckedChanged="chkAutoRefresh_CheckedChanged" ID="chkAutoRefresh" runat="server" AutoPostBack="True" Text="Auto refresh" />
CODE BEHIND:
protected void Page_Load(object sender, EventArgs e)
{
// on every "first" page load which is also every refresh through meta refresh tag
// this one will not be executed when we click checkbox which is a true postback
if (!IsPostBack)
{
Response.Write("Refreshed! " + DateTime.Now);
AutoRefreshSite();
}
}
protected void chkAutoRefresh_CheckedChanged(object sender, EventArgs e)
{
// store value into session
Session["autorefresh"] = chkAutoRefresh.Checked;
// call method where you enable/disable auto refresh
AutoRefreshSite();
}
protected void AutoRefreshSite()
{
if (Session["autorefresh"] != null)
{
// append meta refresh tag
if (bool.Parse(Session["autorefresh"].ToString()))
{
HtmlMeta tag = new HtmlMeta();
tag.HttpEquiv = "refresh";
tag.Content = "5";
Header.Controls.Add(tag);
chkAutoRefresh.Checked = true;
}
}
}