ASP Snippets

Categories






Alerts

Free Alerts

Your email will always be
private and will not be shared.




Follow us on twitter.




Zoom In | Zoom Out


Author is awarded Most Valuable Professional award by Microsoft ASP/ASP.Net

Different ways to create mailto: link - ASP.Net

Author:Mudassar Khan

Here I am explaining different ways to create a mailto link. Generally we associate mailto with a hyperlink but we can also associate it with a Button or Image and also open the mailto email window using from server side event.

 

Simple Mailto

Below is the simplest way to create a mailto using HTML hyperlink.

<a href = "mailto:abc@abc.com">abc@abc.com</a>

 


Mailto using ASP.Net HyperLink Control

The following describes how to use ASP.Net HyperLink to create a mailto link

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



Mailto using Image

In order to create mailto link using image there are two ways

1. Using HTML Link

<a href = "mailto:abc@abc.com"><img src = "images/img.jpg" /></a>


2. Using JavaScript

<img src = "images/img.jpg" onclick = "parent.location='mailto:abc@abc.com'"

style ="cursor:pointer" />

 

 

            

 

Mailto using Button

 

In order to create a mailto using HTML Button you need to take help of JavaScript

 

<input id="Button1" type="button" value="button"

onclick = "parent.location='mailto:abc@abc.com'" />

 

 

Open Mailto Email Window from Server Side Code

You can also open the mailto email window from Asp.net Server Side Code using ClientScript. Below is my button with click event

<asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />

 

And below is the code you need to execute

C#

protected void Button1_Click(object sender, EventArgs e)

{

    //Do some work

    string email = "abc@abc.com";

    ClientScript.RegisterStartupScript(this.GetType(), "mailto",

       "<script type = 'text/javascript'>parent.location='mailto:" + email +

       "'</script>") ;

}

 

VB.Net

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click

        'Do some work

        Dim email As String = "abc@abc.com"

        ClientScript.RegisterStartupScript(Me.GetType(), _

         "mailto", "<script type = 'text/javascript'>" & _

          "parent.location='mailto:" & email & "'</script>")

End Sub



Different ways to create a mailto: link in asp.net

The above code has been tested in the following browsers

Internet Explorer  FireFox  Chrome  Safari  Opera 

* All browser logos displayed above are property of their respective owners.


That’s all for now, hope you liked it.



Posted: Jul 05 2009, 05:45 by Mudassar Khan | Comments (5) RSS comment feed |
Filed under: ASP.Net | C# | JavaScript | Tips | VB.Net

Views: 3848
Page copy protected against web site content infringement by Copyscape


If you like this article, help us grow by bookmarking this page on any social bookmarking site.
Bookmark and Share





Comments

Add comment


 

biuquote
  • Comment
  • Preview
Loading




0  +  0  =   










Community News





Web Hosting SpotLight


Consulting


For consulting and work related queries click here.



Advertise


Advertise with us. For more details click here.


Suggestions


Please provide your valuable suggesstions here.

This Site is hosted on

Lunarpages.com Web Hosting