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.
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.
- Did you try "javascript:window.location.href='New.aspx';" – GavinBrelstaff Commented Mar 21, 2017 at 9:39
-
Why do you need it to be
asp:LinkButton
and not simplea href
? – klashar Commented Mar 21, 2017 at 9:39 - window.location.assign("New.aspx"); – CaptainHere Commented Mar 21, 2017 at 9:40
- Posted how to open on a new window ^^ – Marco Salerno Commented Mar 21, 2017 at 9:49
3 Answers
Reset to default 2window.open("New.aspx", "_self"); // will open in the same windows
window.location.href = "New.aspx"; // will open in a new window
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')");
}
<asp:LinkButton ID="lbiOpen" OnClientClick="window.open('New.aspx', '_self');return false;" Text="Submit" runat="server" />