简体   繁体   中英

How to manage right click “Open in new tab” and “Open in new windows” in Linkbutton in ASP.NET?

I have LinkButton. It populates data and on the base of it, it redirects to the next page. Now the point is that when a user Right Click --> Open in new tab or Open in new window it opens blank windows.

There have ready many issue same like this but none of them work for me.

Here is my code: aspx

<asp:LinkButton runat="server" 
                ID="Link_SignUp" 
                OnClick="Link_SignUp_Click">Signup Now!
</asp:LinkButton>

Click event

protected void Link_SignUp_Click(object sender, EventArgs e)
{
    //populate data
    //make URL -- DotnetNuke
    string miUrl = base.EditUrl("", "", "portal_profile");
    //redirec to URL
    Response.Redirect(miUrl, true);
}

I have tried few solutions but none of them helped me.
I have tried to set Form property target = _blank and it worked but I have set it manually when on clientclick.

I want natural behavior.

1- When a user right clicks and selects "Open in new tab", it should open in a new tab.

2- When user right clicks and selects "Open in new window", it should open in a new window.

3- When user left clicks, it should open in the same page.

Try this:

Create a hyperlink in your aspx view, instead of the link button.

On Page_Load, build up the relevant URL using the code you use in the Link_SignUp_Click event. Then, immediately after, you can assign the hyperlinks NavigateUrl property like so:

ie

protected void Page_Load(object sender, EventArgs e)
{
    string miUrl = base.EditUrl("", "", "portal_profile");
    HyperLinkID.NavigateUrl = miUrl;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM