0

I want open Outlook if I click on a Button in a ListView. how this...

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

I have a ...

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

without a url. The Url get this LinkButton from the ListView and it works but i don't can activate this LinkButton after this :(

how this...

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?????
    }
}

How I can activate the LinkButton wthout click on this?

Erwin
  • 4,757
  • 3
  • 31
  • 41
Tarasov
  • 3,625
  • 19
  • 68
  • 128
  • Why do you use an ItemCommand for this? Can't you set the mailto: link directly in your listview with eval. – Erwin Aug 29 '12 at 12:34

4 Answers4

1

Try using <asp:HyperLink />, documented here:

<asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl = "mailto:abc@example.com" Text ="abc@example.com"></asp:HyperLink>
woz
  • 10,888
  • 3
  • 34
  • 64
1

just use link

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

You can use in code behind as linkbutton, but he offers others functionalities

hl.NavigateUrl =  "mailto:" + mailto;

Tarasov You find all properties here

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

Aghilas Yakoub
  • 28,516
  • 5
  • 46
  • 51
1

Use hyperlink instead of link button

 <asp:HyperLink ID="HyperLink1" runat="server" 
NavigateUrl="mailto:user@example.com" >HyperLink</asp:HyperLink>
Satinder singh
  • 10,100
  • 16
  • 60
  • 102
1

If you're stuck on using a button, then set the ClientClick property. Use return false; to cancel the postback. If you want the postback, then leave it off.

LinkButton1.ClientClick = "window.open('mailto:someone@somewhere.com', 'email'); return false;";
Chris Gessler
  • 22,727
  • 7
  • 57
  • 83