That's it. If js is disabled, this second line will kick off and postback. Perfect.
Still, we don't want to do this everytime. We want to do this for the first request only, so what we can do is set a serverside flag in session state. I don't really recommend using session state because I find sessions to be unreliable, but that's just me. You basically have no control on when the session recycles. My preference lies in the profile provider(which is going to persist the value in the database and in style), however for simplicity, i'm setting a flag in session state.
Following is the code :
<%@ Page Language="C#" %>
do it in init, otherwise you cannot
set ScriptManager.EnablePartialRendering property
protected void Page_Init(object sender, EventArgs e)
bool notSet = string.IsNullOrEmpty(this.Request.QueryString["supportsjs"]);
string url = this.Request.Url.OriginalString;
if (notSet && Session["supportsjs"] == null)
string queryStringKey = (this.Request.QueryString.Count > 0) ?
"&supportsjs=" : "?supportsjs=";
string jsTesterScript = string.Format(
"script", url, queryStringKey);
if (Session["supportsjs"] == null)
Session["supportsjs"] = false;// default, assume false
// if our js code posted back,
// and we still hold default assumption,
// then client does indeed support js
// so update the session
if (!notSet && !(bool)Session["supportsjs"])
Session["supportsjs"] = true;
ScriptManager1.EnablePartialRendering = (bool)Session["supportsjs"];
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server" />
<h1>outside updatepanel : <%= DateTime.Now %></h1>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<h1>Inside updatepanel : <%= DateTime.Now %></h1>
<asp:Button ID="Button1" runat="server" Text="Button" />