Showing posts with label browser. Show all posts
Showing posts with label browser. Show all posts

Thursday, 13 February 2014

PRevent Re-submission of Data on Browser reload in C#.NET

On .aspx page write take a hidden field:

<asp:HiddenField id="hdncheckreload" runat="server" />


On .cs page write a function to check whether it's first time call event or reloaded......

public bool notIsRefresh()
        {
            bool retVal = false;
            if (Session["match"] == null || Session["match"].ToString() == hdncheckreload.Value)
                retVal = true;
            Session["match"] = DateTime.Now.Ticks;
            hdncheckreload.Value = Session["match"].ToString();
            return retVal;
        }

call this method on event which is reloaded such as button click event, form submission etc...

Friday, 29 November 2013

HOw to Clear Cache,Cookies and History of All Browser in C#.net on Button Click

Use this code on your button click event:

protected void LinkButton1_Click(object sender, EventArgs e)
        {
            Session.Abandon();
            Session["AEmail"] = null;
            Session.Clear();
            ClearCache();
            clearchachelocalall();
            Response.Redirect("../Default.aspx");

        }
        public static void ClearCache()
        {
            HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.NoCache);
            HttpContext.Current.Response.Cache.SetExpires(DateTime.Now);
            HttpContext.Current.Response.Cache.SetNoServerCaching();
            HttpContext.Current.Response.Cache.SetNoStore();
            HttpContext.Current.Response.Cookies.Clear();
            HttpContext.Current.Request.Cookies.Clear();
        }

        private void clearchachelocalall()
        {
            string GooglePath = Environment.GetEnvironmentVariable("USERPROFILE") + @"\AppData\Local\Google\Chrome\User Data\Default\";
            string MozilaPath = Environment.GetEnvironmentVariable("USERPROFILE") + @"\AppData\Roaming\Mozilla\Firefox\";
            string Opera1 = Environment.GetEnvironmentVariable("USERPROFILE") + @"\AppData\Local\Opera\Opera";
            string Opera2 = Environment.GetEnvironmentVariable("USERPROFILE") + @"\AppData\Roaming\Opera\Opera";
            string Safari1 = Environment.GetEnvironmentVariable("USERPROFILE") + @"\AppData\Local\Apple Computer\Safari";
            string Safari2 = Environment.GetEnvironmentVariable("USERPROFILE") + @"\AppData\Roaming\Apple Computer\Safari";
            string IE1 = Environment.GetEnvironmentVariable("USERPROFILE") + @"\AppData\Local\Microsoft\Intern~1";
            string IE2 = Environment.GetEnvironmentVariable("USERPROFILE") + @"\AppData\Local\Microsoft\Windows\History";
            string IE3 = Environment.GetEnvironmentVariable("USERPROFILE") + @"\AppData\Local\Microsoft\Windows\Tempor~1";
            string IE4 = Environment.GetEnvironmentVariable("USERPROFILE") + @"\AppData\Roaming\Microsoft\Windows\Cookies";
            string Flash = Environment.GetEnvironmentVariable("USERPROFILE") + @"\AppData\Roaming\Macromedia\Flashp~1";

            //Call This Method ClearAllSettings and Pass String Array Param
            ClearAllSettings(new string[] { GooglePath, MozilaPath, Opera1, Opera2, Safari1, Safari2, IE1, IE2, IE3, IE4, Flash });
           
        }

        public void ClearAllSettings(string[] ClearPath)
        {
            foreach (string HistoryPath in ClearPath)
            {
                if (Directory.Exists(HistoryPath))
                {
                    DoDelete(new DirectoryInfo(HistoryPath));
                }

            }
        }

        void DoDelete(DirectoryInfo folder)
        {
            try
            {

                foreach (FileInfo file in folder.GetFiles())
                {
                    try
                    {
                        file.Delete();
                    }
                    catch
                    { }

                }
                foreach (DirectoryInfo subfolder in folder.GetDirectories())
                {
                    DoDelete(subfolder);
                }
            }
            catch
            {
            }
        }

Friday, 9 August 2013

Open Page in New tab of Same browser with update panel C#.NET

Try this on Any event such as button click,dropdown_SelectedIndexChanged.......etc i am sure it is work for you...........

ScriptManager.RegisterStartupScript(Page, typeof(System.Web.UI.Page),
                     "click", @"<script>window.open('StudentProfile.aspx','_newtab');</script>", false);