link button property to open in new tab?

前端 未结 8 1310
野趣味
野趣味 2020-11-27 07:15

In my application I have some link buttons there but when I right click on them I cannot (they are in disable mode) find the menu items Open in new tab or

相关标签:
8条回答
  • 2020-11-27 07:56

    This is not perfect, but it works.

    <asp:LinkButton id="lbnkVidTtile1" runat="Server" 
        CssClass="bodytext" Text='<%# Eval("newvideotitle") %>'
        OnClientClick="return PostToNewWindow();"  />
    
    <script type="text/javascript">
    function PostToNewWindow()
    {
        originalTarget = document.forms[0].target;
        document.forms[0].target='_blank';
        window.setTimeout("document.forms[0].target=originalTarget;",300);
        return true;
    }
    </script>
    
    0 讨论(0)
  • 2020-11-27 08:02

    From the docs:

    Use the LinkButton control to create a hyperlink-style button on the Web page. The LinkButton control has the same appearance as a HyperLink control, but has the same functionality as a Button control. If you want to link to another Web page when the control is clicked, consider using the HyperLink control.

    As this isn't actually performing a link in the standard sense, there's no Target property on the control (the HyperLink control does have a Target) - it's attempting to perform a PostBack to the server from a text link.

    Depending on what you are trying to do you could either:

    1. Use a HyperLink control, and set the Target property
    2. Provide a method to the OnClientClick property that opens a new window to the correct place.
    3. In your code that handles the PostBack add some JavaScript to fire on PageLoad that will open a new window correct place.
    0 讨论(0)
  • 2020-11-27 08:03

    When the LinkButton Enabled property is false it just renders a standard hyperlink. When you right click any disabled hyperlink you don't get the option to open in anything.

    try

    lbnkVidTtile1.Enabled = true;
    

    I'm sorry if I misunderstood. Could I just make sure that you understand the purpose of a LinkButton? It is to give the appearance of a HyperLink but the behaviour of a Button. This means that it will have an anchor tag, but there is JavaScript wired up that performs a PostBack to the page. If you want to link to another page then it is recommended here that you use a standard HyperLink control.

    0 讨论(0)
  • 2020-11-27 08:03
     <asp:LinkButton ID="LinkButton1" runat="server" target="_blank">LinkButton</asp:LinkButton>
    

    Use target="_blank" because It creates anchor markup. the following HTML is generated for above code

    <a id="ctl00_ContentPlaceHolder1_LinkButton1" target="_blank" href="javascript:__doPostBack('ctl00$ContentPlaceHolder1$LinkButton1','')">LinkButton</a>
    
    0 讨论(0)
  • 2020-11-27 08:04

    It throws error.

    Microsoft JScript runtime error: 'aspnetForm' is undefined

    0 讨论(0)
  • 2020-11-27 08:05

    Here is your Tag.

    <asp:LinkButton ID="LinkButton1" runat="server">Open Test Page</asp:LinkButton>
    

    Here is your code on the code behind.

    LinkButton1.Attributes.Add("href","../Test.aspx")
    LinkButton1.Attributes.Add("target","_blank")
    

    Hope this will be helpful for someone.

    Edit To do the same with a link button inside a template field, use the following code.

    Use GridView_RowDataBound event to find Link button.

    Dim LB as LinkButton = e.Row.FindControl("LinkButton1")         
    LB.Attributes.Add("href","../Test.aspx")  
    LB.Attributes.Add("target","_blank")
    
    0 讨论(0)
提交回复
热议问题