ASP.NET Redirect to open a new browser window using javascript window.Open method

To  redirect the page in new window there is no readymade methode in asp.net. To overcome this lack of readymade function, we need to do some custom coding and it will only achieve by using javascript Window.Open Methode. I have created the methode in c#.nnet to redirect the desired page in new window.

Following is my methode defination..

 public static void Redirect(string url, string target, string windowFeatures)
        {
            HttpContext context = HttpContext.Current;
            Page page = (Page)context.Handler;
           

            string script;
            if (!String.IsNullOrEmpty(windowFeatures))
            {
                script = @"window.open(""{0}"", ""{1}"", ""{2}"");";
            }
            else
            {
                script = @"window.open(""{0}"", ""{1}"");";
            }

            script = String.Format(script, url, target, windowFeatures);
            ScriptManager.RegisterStartupScript(page,
                typeof(Page),
                "Redirect",
                script,
                true);
        }

Hope it will help you...............

I am awaiting your responces...


Comments

Popular posts from this blog

Angular User Session Timeout example step by step

Implement Nlog in .Net core MVC application part 1

I have created an application to extract text from image using AI

Implement Logging in CSV file using Nlog in .net core MVC application- part 2

Create Chat bot application using Python, Streamlit and Gemini AI