【问题标题】:How I can activate a LinkButton without click on this?如何在不单击此按钮的情况下激活 LinkBut​​ton?
【发布时间】:2012-08-29 12:28:55
【问题描述】:

如果我单击 ListView 中的按钮,我想打开 Outlook。这是怎么...

<a href="mailto:user@example.com">Send email to user@example.com</a>

我有一个...

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

没有网址。 Url 从 ListView 获取此 LinkBut​​ton 并且它可以工作,但在此之后我无法激活此 LinkBut​​ton :(

这是怎么...

protected void myListView_ItemCommand(object sender, ListViewCommandEventArgs e)
{
    if (e.CommandName == "mailto")
    {
        int index = Convert.ToInt32(e.CommandArgument);

        LinkButton lb = (LinkButton)myListView.Items[index].FindControl("Label2");

        string mailto = lb.Text;

        LinkButton1.PostBackUrl = "mailto:" + mailto;
        LinkButton1.ResolveClientUrl("mailto:" + mailto); //Here?????
    }
}

如何在不点击的情况下激活链接按钮?

【问题讨论】:

  • 你为什么要使用 ItemCommand 呢?你不能设置mailto:直接在你的listview中用eval链接。

标签: c# asp.net email listview linkbutton


【解决方案1】:

如果您坚持使用按钮,请设置 ClientClick 属性。使用return false; 取消回发。如果您想要回发,请不要使用它。

LinkButton1.ClientClick = "window.open('mailto:someone@somewhere.com', 'email'); return false;";

【讨论】:

    【解决方案2】:

    尝试使用&lt;asp:HyperLink /&gt;,记录在案的here

    <asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl = "mailto:abc@example.com" Text ="abc@example.com"></asp:HyperLink>
    

    【讨论】:

      【解决方案3】:

      只使用链接

      <asp:HyperLink ID="hl" runat="server" NavigateUrl = ..." Text ="link"></asp:HyperLink>
      

      你可以在代码后面作为链接按钮使用,但他提供了其他功能

      hl.NavigateUrl =  "mailto:" + mailto;
      

      塔拉索夫您可以在这里找到所有属性

      http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.hyperlink.aspx

      【讨论】:

        【解决方案4】:

        使用超链接代替链接按钮

         <asp:HyperLink ID="HyperLink1" runat="server" 
        NavigateUrl="mailto:user@example.com" >HyperLink</asp:HyperLink>
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2014-11-20
          • 1970-01-01
          • 2012-01-21
          • 1970-01-01
          • 2020-03-05
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多