I'm trying to open a page in new tab/window on button click.I tried in the google got this code but its not working.
Can anybody help me with this?
<asp:Button ID="btn" runat="Server" Text="SUBMIT"
OnClick="btnNewEntry_Click" OnClientClick="aspnetForm.target ='_blank';"/>
protected void btnNewEntry_Click(object sender, EventArgs e)
{
Response.Redirect("CMS_1.aspx");
}
When I use this I'm getting error saying
Microsoft JScript runtime error: 'aspnetForm' is undefined.
You can do something like this :
<asp:Button ID="Button1" runat="server" Text="Button"
onclick="Button1_Click" OnClientClick="document.forms[0].target = '_blank';" />
Wouldn't you be better off with
<asp:HyperLink ID="HyperLink1" runat="server"
NavigateUrl="CMS_1.aspx"
Target="_blank">
Click here
</asp:HyperLink>
Because, to replicate your desired behavior on an asp:Button
, you have to call window.open
on the OnClientClick
event of the button which looks a lot less cleaner than the above solution. Plus asp:HyperLink
is there to handle scenarios like this.
If you want to replicate this using an asp:Button
, do this.
<asp:Button ID="btn" runat="Server"
Text="SUBMIT"
OnClientClick="javascript:return openRequestedPopup();"/>
JavaScript function.
var windowObjectReference;
function openRequestedPopup() {
windowObjectReference = window.open("CMS_1.aspx",
"DescriptiveWindowName",
"menubar=yes,location=yes,resizable=yes,scrollbars=yes,status=yes");
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With