This is an interesting question to every one reading, please specify the working code for the current condition :
" I am making an ASP.Net website with tons of JavaScript Validation and so so .... now as i have mentioned that my whole project is JavaScript based , what i want is that when a user open my ASP.Net website , my website must check whether JavaScript is enabled or not ? if YES(enabled) then proceed to main page , if NO(disabled) then redirect to Error.aspx page which will be in my project ..... if user Enable the JavaScript after getting the Error.aspx page on screen and refreshes the page , then Redirect to Mainpage.aspx" ... please provide the code as soon as possible , thanks !

KalaiPosted Feb 14, 2014, 1:55 AM
Try the below code. Enable and Disable JS in browser.
Main.aspx
<script type="text/javascript">function load() {alert("ok");}script>
<style type="text/css">div.noscript {display: block;text-align: center;color: white;font-weight: 700;background: #D53333;margin: 0 auto;padding: 4px;}style>
<body>
<form id="form1" runat="server">
<asp:Button ID="btn" runat="server"Text="Test"OnClientClick="load(); return false;" />
<noscript>
<div class="noscript"id="js-warning">
<meta http-equiv="Refresh"content="1; URL=http://localhost:58044/error.aspx">
To be able to access all of our features, you need a browser that supports JavaScript, and it needs to be enabled.
div>
noscript>
form>
body>
html>
Error.aspx.cs
protected void Page_Load(object sender, EventArgs e)
{
if (Session["JSChecked"] == null)
//JSChecked -indicates if it tried to run the javascript version
{
// prevent infinite loop
Session["JSChecked"] = "Checked";
string path = Request.Url + "?JScript=1";
Page.ClientScript.RegisterStartupScript(this.GetType(), "redirect","window.location.href='" + path + "';", true);
}
if (Request.QueryString["JScript"] == null)
{
Response.Write("JavaScript is not enabled.");
Session.Remove("JSChecked");
}
else
{
Response.Write("JavaScript is enabled.");
Response.Redirect("http://localhost:58044/Main.aspx");
}
}