Click here to Skip to main content
15,886,199 members
Articles / Web Development / ASP.NET

Check Whether JavaScript and Cookie are Enabled using Custom Control

Rate me:
Please Sign up or sign in to vote.
5.00/5 (2 votes)
9 Apr 2010CPOL4 min read 37K   721   18  
A custom control for checking whether JavaScript and Cookie are enabled in the client browser
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
using Web.Utility;

namespace JavaScriptCookieChecker
{
    public partial class _Default : System.Web.UI.Page
    {

        private const string BrowserCheckJavaScript = "Either your web browser is not capable of supporting JavaScript at all or the use of JavaScript has been purposely disabled.";

        private const string BrowserCheckCookie = "The use of Cookie in your browser has been purposely disabled.";
	


        protected void Page_Load(object sender, EventArgs e)
        {

            if (IsPostBack)
                CheckBrowser();
        }

        private void CheckBrowser()
        {
            StringBuilder error = new StringBuilder();

            if (this.BrowserChecker1.BrowserJavaScriptStatus == BrowserStatus.Disabled)
                error.Append(BrowserCheckJavaScript);

            if (this.BrowserChecker1.BrowserCookieStatus == BrowserStatus.Disabled)
                error.Append(BrowserCheckCookie);

            if (error.Length > 0)
                this.lblMessage.Text = error.ToString();
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior)
Canada Canada
Microsoft Certified Professional Developer (MCPD).
C#, ASP.NET, SharePoint, Microsoft Dynamics CRM, GIS

Comments and Discussions