Olga
Olga

Reputation: 117

How to open URL in same window and in same tab

I have this LinkButton:

<asp:LinkButton ID="lbiOpen" runat="server" />

and my Code behind:

protected void Page_Load(object sender, EventArgs e)
{
    lbiOpen.Attributes.Add("onclick", "javascript:window.location.href('New.aspx');"); 
}

If a user clicks on the LinkButton a popup should open. But it doesn't work. When I click on nothing happens.

When I Change window.location.href = window.open it works, but it opens in another tab.

Upvotes: 2

Views: 9783

Answers (3)

Abdul A. Chaudhary
Abdul A. Chaudhary

Reputation: 11

<asp:LinkButton ID="lbiOpen" OnClientClick="window.open('New.aspx', '_self');return false;" Text="Submit" runat="server" />

Upvotes: 1

Marco Salerno
Marco Salerno

Reputation: 5203

This works for me:

<asp:LinkButton ID="lbiOpen" runat="server">Example</asp:LinkButton>


    protected void Page_Load(object sender, EventArgs e)
    {
        lbiOpen.Attributes.Add("onclick", "window.open('New.aspx', 'New Window', 'width=200,height=100')");
    }

Upvotes: 1

Kapila Perera
Kapila Perera

Reputation: 857

window.open("New.aspx", "_self"); // will open in the same windows

window.location.href = "New.aspx"; // will open in a new window

Upvotes: 2

Related Questions