0

I have a .net project and I've been trying to use a linkbutton in a such a way that it will not open the link on another page/tab. At the moment what I have open the link on another page. Please help.

My ascx page code below:

 <td>
    <asp:LinkButton ID="ApproveButton" runat="server" Text="Approval" CssClass="btn btn-primary btn-xs" OnClientClick="window.open('/Licence-Application/Applicant-Approval-Page');"/>
</td>

I have tried window.open, window.show, Response.Redirect, window.location, location.href with no luck. It's either it keeps opening the same page or gives an error or open on a new tab.

MRizwan33
  • 2,723
  • 6
  • 31
  • 42
ToluOwo
  • 3
  • 1
  • 4
  • Possible duplicate of [How to make (link)button function as hyperlink?](https://stackoverflow.com/questions/14034960/how-to-make-linkbutton-function-as-hyperlink) – Soham Dasgupta May 15 '18 at 14:12
  • Can you tell us a little more of the error you're getting when you try `location.href`? – Soham Dasgupta May 15 '18 at 14:15
  • Below is the error I got on using 'location.href' 'Error: Enrolled Applicants List is currently unavailable. DotNetNuke.Services.Exceptions.ModuleLoadException: The server tag is not well formed. ---> System.Web.HttpParseException: The server tag is not well formed. ---> System.Web.HttpException: The server tag is not well formed. at System.Web.UI.TemplateParser.ProcessError(String message) at System.Web.UI.TemplateParser.ParseStringInternal(String text, Encoding fileEncoding) at System.Web.UI.TemplateParser.ParseString(String text, VirtualPath virtualPath, Encoding fileEncoding)' – ToluOwo May 15 '18 at 14:49

1 Answers1

0

Change your code to use location.href instead of window.open. window.open will always open a new tab.

<asp:Button ID="ApproveButton" runat="server" Text="Approval" CssClass="btn btn-primary btn-xs" OnClientClick="location.href = '/Licence-Application/Applicant-Approval-Page';"/>

or

<asp:LinkButton runat="server" ID="ApproveButton" href="/Licence-Application/Applicant-Approval-Page" CssClass="btn btn-primary btn-xs">Button Text</asp:LinkButton>
Soham Dasgupta
  • 5,061
  • 24
  • 79
  • 125
  • Not sure what he's doing here but this solution definitely works. Check [this](https://stackoverflow.com/a/14035072/238631) out. – Soham Dasgupta May 15 '18 at 14:17
  • 1
    @SohamDasgupta is right. I only used 'location.href' but I just tried only 'href' and it worked perfectly. Thank you very much. – ToluOwo May 15 '18 at 14:43