How to open new tab on ASP C# and focus stay on current page then current page redirect to another page on click button?

StackOverflow https://stackoverflow.com/questions/22533259

Question

I already tried this code:

 protected void btnLogin_Click(object sender, EventArgs e)
    {
        String username = tbxUserName.Text;
        String password = tbxPassword.Text;
        String url = "http://localhost/drupal/login.php?user_name="+username+"&password="+password;

        Page.ClientScript.RegisterStartupScript(
            this.GetType(), 
            "OpenWindow",
            "var win = window.open('" + url + "','_newtab'); self.focus();", 
            true);

        Response.Redirect(url);
    }

That code just redirect to another page, but if I remove Response.Redirect(url), browser open new tab but focus to new tab.

Any body can help?

Was it helpful?

Solution

Yes, you should remove Response.Redirect(url);, otherwise your code above it is lost. What browser are you using? It's not only you code that controls this behaviour. The browsers have settings for that too. For example, in Internet Explorer 11, go to Internet Options and click on the Tabs button on the general tab. Notice the setting Always switch to new tabs when they are created, if it is checked, then it will behave the way you described it. Clear it and see what happens.

OTHER TIPS

You can open the page in a new window...

ScriptManager.RegisterStartupScript(this, this.GetType(), "onclick", "javascript:window.open( '../../drupal/login.php','_blank','height=600px,width=600px,scrollbars=1');", true);

After that redirect to the required page...

Response.Redirect(url);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top