Whilda Chaq
Whilda Chaq

Reputation: 364

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

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?

Upvotes: 1

Views: 3239

Answers (2)

Racil Hilan
Racil Hilan

Reputation: 25351

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.

Upvotes: 1

Jameem
Jameem

Reputation: 1838

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);

Upvotes: 0

Related Questions