How to use Eval / Bind to create a mailto link?

N

Nahom Tijnam

Hi,

In my gridview or datalist control, I know how to use the Eval or Bind
method to bind a control property to a data as follows:
<asp:HyperLink ID="email" runat="server" NavigateUrl='<%# Eval("email",
"mailto:{0}") %>'>Email me</asp:HyperLink>
would give result as <a href="mailto:[email protected]">Email me</a>

But is it possible to get a mailto output as below?
<a href="mailto:[email protected]?subject=contact Us">Email me</a>

Here, the difference is that I am trying to bind 2 different data values to
the same property of the control, one for the response email address, and
another for the subject.
mailto:<email from db>?subject=<category from db>

Is this possible, and how could this be done?

Thanks in advance.
 
E

Elton Wang

Hi Nahom,

Although GridView supports multi-parameters in its HyperLinkField, it's for
Hyperlink rather than for mailto link. You need use GridView_RowDataBound
event to build mailto link like follows:

if (e.Row.RowType == DataControlRowType.DataRow)
{
DataRowView drv = e.Row.DataItem as DataRowView;
HyperLink link = e.Row.Cells[link_field_index].Controls[0] as
HyperLink;
link.NavigateUrl = "mailto:" + drv["mail_address"].ToString() +
"?subject=" + drv["subject"].ToString();
}

HTH
 
S

Steven Cheng[MSFT]

Thanks for Elton's good suggestion.

Hi Elton,

For your scenario that we need advanced customization on the hyperlink
control's column, I'd suggest you consider using Template Column(field),
thus, we can either use the RowDataBound event to find the control and set
the property or fields we want (as Elton has demonstrated....) or define a
helper function in page class and use it in Data Bound template (aspx )
inline. e.g:

<asp:HyperLink ID="email" runat="server" NavigateUrl='<%# HelperFunc(
Container.DataItem) %>'>Email me</asp:HyperLink>


HelperFunc is a helper function defined in page class which accept the
databound item and return a string to represent the url string....

Hope also helps. Thanks,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)


--------------------
| From: "Elton Wang" <[email protected]>
| References: <[email protected]>
| Subject: Re: How to use Eval / Bind to create a mailto link?
| Date: Sun, 15 Jan 2006 15:21:29 -0500
| Lines: 45
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2900.2180
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180
| X-RFC2646: Format=Flowed; Original
| Message-ID: <[email protected]>
| Newsgroups: microsoft.public.dotnet.framework.aspnet.datagridcontrol
| NNTP-Posting-Host: 69.158.28.148
| Path: TK2MSFTNGXA02.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP11.phx.gbl
| Xref: TK2MSFTNGXA02.phx.gbl
microsoft.public.dotnet.framework.aspnet.datagridcontrol:15072
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.datagridcontrol
|
| Hi Nahom,
|
| Although GridView supports multi-parameters in its HyperLinkField, it's
for
| Hyperlink rather than for mailto link. You need use GridView_RowDataBound
| event to build mailto link like follows:
|
| if (e.Row.RowType == DataControlRowType.DataRow)
| {
| DataRowView drv = e.Row.DataItem as DataRowView;
| HyperLink link = e.Row.Cells[link_field_index].Controls[0] as
| HyperLink;
| link.NavigateUrl = "mailto:" + drv["mail_address"].ToString()
+
| "?subject=" + drv["subject"].ToString();
| }
|
| HTH
|
| | > Hi,
| >
| > In my gridview or datalist control, I know how to use the Eval or Bind
| > method to bind a control property to a data as follows:
| > <asp:HyperLink ID="email" runat="server" NavigateUrl='<%# Eval("email",
| > "mailto:{0}") %>'>Email me</asp:HyperLink>
| > would give result as <a href="mailto:[email protected]">Email me</a>
| >
| > But is it possible to get a mailto output as below?
| > <a href="mailto:[email protected]?subject=contact Us">Email me</a>
| >
| > Here, the difference is that I am trying to bind 2 different data
values
| > to
| > the same property of the control, one for the response email address,
and
| > another for the subject.
| > mailto:<email from db>?subject=<category from db>
| >
| > Is this possible, and how could this be done?
| >
| > Thanks in advance.
| >
| > --
| > Nahom Tijnam
| > Dubai, UAE
|
|
|
 
E

Elton Wang

Hi Steven,

Good suggestion! Thanks.

Elton

Steven Cheng said:
Thanks for Elton's good suggestion.

Hi Elton,

For your scenario that we need advanced customization on the hyperlink
control's column, I'd suggest you consider using Template Column(field),
thus, we can either use the RowDataBound event to find the control and set
the property or fields we want (as Elton has demonstrated....) or define
a
helper function in page class and use it in Data Bound template (aspx )
inline. e.g:

<asp:HyperLink ID="email" runat="server" NavigateUrl='<%# HelperFunc(
Container.DataItem) %>'>Email me</asp:HyperLink>


HelperFunc is a helper function defined in page class which accept the
databound item and return a string to represent the url string....

Hope also helps. Thanks,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)


--------------------
| From: "Elton Wang" <[email protected]>
| References: <[email protected]>
| Subject: Re: How to use Eval / Bind to create a mailto link?
| Date: Sun, 15 Jan 2006 15:21:29 -0500
| Lines: 45
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2900.2180
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180
| X-RFC2646: Format=Flowed; Original
| Message-ID: <[email protected]>
| Newsgroups: microsoft.public.dotnet.framework.aspnet.datagridcontrol
| NNTP-Posting-Host: 69.158.28.148
| Path: TK2MSFTNGXA02.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP11.phx.gbl
| Xref: TK2MSFTNGXA02.phx.gbl
microsoft.public.dotnet.framework.aspnet.datagridcontrol:15072
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.datagridcontrol
|
| Hi Nahom,
|
| Although GridView supports multi-parameters in its HyperLinkField, it's
for
| Hyperlink rather than for mailto link. You need use
GridView_RowDataBound
| event to build mailto link like follows:
|
| if (e.Row.RowType == DataControlRowType.DataRow)
| {
| DataRowView drv = e.Row.DataItem as DataRowView;
| HyperLink link = e.Row.Cells[link_field_index].Controls[0]
as
| HyperLink;
| link.NavigateUrl = "mailto:" +
drv["mail_address"].ToString()
+
| "?subject=" + drv["subject"].ToString();
| }
|
| HTH
|
| | > Hi,
| >
| > In my gridview or datalist control, I know how to use the Eval or Bind
| > method to bind a control property to a data as follows:
| > <asp:HyperLink ID="email" runat="server" NavigateUrl='<%#
Eval("email",
| > "mailto:{0}") %>'>Email me</asp:HyperLink>
| > would give result as <a href="mailto:[email protected]">Email me</a>
| >
| > But is it possible to get a mailto output as below?
| > <a href="mailto:[email protected]?subject=contact Us">Email me</a>
| >
| > Here, the difference is that I am trying to bind 2 different data
values
| > to
| > the same property of the control, one for the response email address,
and
| > another for the subject.
| > mailto:<email from db>?subject=<category from db>
| >
| > Is this possible, and how could this be done?
| >
| > Thanks in advance.
| >
| > --
| > Nahom Tijnam
| > Dubai, UAE
|
|
|
 
S

Steven Cheng[MSFT]

Hi Nahom,

Does our suggest help you some? If anything else we can help, please feel
free to post here.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
--------------------
| From: "Elton Wang" <[email protected]>
| References: <[email protected]>
<[email protected]>
<[email protected]>
| Subject: Re: How to use Eval / Bind to create a mailto link?
| Date: Mon, 16 Jan 2006 09:08:21 -0500
| Lines: 113
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2900.2180
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180
| X-RFC2646: Format=Flowed; Original
| Message-ID: <[email protected]>
| Newsgroups: microsoft.public.dotnet.framework.aspnet.datagridcontrol
| NNTP-Posting-Host: 204.101.136.100
| Path: TK2MSFTNGXA02.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP11.phx.gbl
| Xref: TK2MSFTNGXA02.phx.gbl
microsoft.public.dotnet.framework.aspnet.datagridcontrol:15076
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.datagridcontrol
|
| Hi Steven,
|
| Good suggestion! Thanks.
|
| Elton
|
| | > Thanks for Elton's good suggestion.
| >
| > Hi Elton,
| >
| > For your scenario that we need advanced customization on the hyperlink
| > control's column, I'd suggest you consider using Template Column(field),
| > thus, we can either use the RowDataBound event to find the control and
set
| > the property or fields we want (as Elton has demonstrated....) or
define
| > a
| > helper function in page class and use it in Data Bound template (aspx )
| > inline. e.g:
| >
| > <asp:HyperLink ID="email" runat="server" NavigateUrl='<%# HelperFunc(
| > Container.DataItem) %>'>Email me</asp:HyperLink>
| >
| >
| > HelperFunc is a helper function defined in page class which accept the
| > databound item and return a string to represent the url string....
| >
| > Hope also helps. Thanks,
| >
| > Steven Cheng
| > Microsoft Online Support
| >
| > Get Secure! www.microsoft.com/security
| > (This posting is provided "AS IS", with no warranties, and confers no
| > rights.)
| >
| >
| > --------------------
| > | From: "Elton Wang" <[email protected]>
| > | References: <[email protected]>
| > | Subject: Re: How to use Eval / Bind to create a mailto link?
| > | Date: Sun, 15 Jan 2006 15:21:29 -0500
| > | Lines: 45
| > | X-Priority: 3
| > | X-MSMail-Priority: Normal
| > | X-Newsreader: Microsoft Outlook Express 6.00.2900.2180
| > | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180
| > | X-RFC2646: Format=Flowed; Original
| > | Message-ID: <[email protected]>
| > | Newsgroups: microsoft.public.dotnet.framework.aspnet.datagridcontrol
| > | NNTP-Posting-Host: 69.158.28.148
| > | Path: TK2MSFTNGXA02.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP11.phx.gbl
| > | Xref: TK2MSFTNGXA02.phx.gbl
| > microsoft.public.dotnet.framework.aspnet.datagridcontrol:15072
| > | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.datagridcontrol
| > |
| > | Hi Nahom,
| > |
| > | Although GridView supports multi-parameters in its HyperLinkField,
it's
| > for
| > | Hyperlink rather than for mailto link. You need use
| > GridView_RowDataBound
| > | event to build mailto link like follows:
| > |
| > | if (e.Row.RowType == DataControlRowType.DataRow)
| > | {
| > | DataRowView drv = e.Row.DataItem as DataRowView;
| > | HyperLink link =
e.Row.Cells[link_field_index].Controls[0]
| > as
| > | HyperLink;
| > | link.NavigateUrl = "mailto:" +
| > drv["mail_address"].ToString()
| > +
| > | "?subject=" + drv["subject"].ToString();
| > | }
| > |
| > | HTH
| > |
| > | | > | > Hi,
| > | >
| > | > In my gridview or datalist control, I know how to use the Eval or
Bind
| > | > method to bind a control property to a data as follows:
| > | > <asp:HyperLink ID="email" runat="server" NavigateUrl='<%#
| > Eval("email",
| > | > "mailto:{0}") %>'>Email me</asp:HyperLink>
| > | > would give result as <a href="mailto:[email protected]">Email me</a>
| > | >
| > | > But is it possible to get a mailto output as below?
| > | > <a href="mailto:[email protected]?subject=contact Us">Email me</a>
| > | >
| > | > Here, the difference is that I am trying to bind 2 different data
| > values
| > | > to
| > | > the same property of the control, one for the response email
address,
| > and
| > | > another for the subject.
| > | > mailto:<email from db>?subject=<category from db>
| > | >
| > | > Is this possible, and how could this be done?
| > | >
| > | > Thanks in advance.
| > | >
| > | > --
| > | > Nahom Tijnam
| > | > Dubai, UAE
| > |
| > |
| > |
| >
|
|
|
 
C

Captain EO

Wondering if you can help me.

I am using mailto in a URL. Basically I want the URL to open outlook --
this is working fine. However I want the email created to include my outlook
signature, but when I use mailto I get a blank email even though I have
signatures turned on. Any ideas on how I can get the signature into the email.

Thanks
 
S

Scott M.

Let me clarify...

The mailto: protocol of a link does not specify that Outlook should open.
It specifies that the browser should open *whatever* email program the
browser has its default set to. Even if Outlook is that program, you may
notice that when you click the link a new mail message is created by Outlook
itself does not open. Because of this order, the signature won't be added.

If you absolutely need this functionality, you should move away from the
client-side mailto: and change your code to server-side code that automates
Outlook.
 
E

Eliyahu Goldin

If you absolutely need this functionality, you should move away from the
client-side mailto: and change your code to server-side code that
automates Outlook.
But the user is on the client side, how can serve-side automation help?
 
S

Scott M.

The mail message does not have to originate at the client. Whoever said it
had to? The application could provide a web based form for the user to fill
out and when the user is done, that client-data can be used to populate a
server generated mail message.

From the way the OP was written, it seems that just one particular signature
is needed on the outbound message.

Eliyahu Goldin said:
If you absolutely need this functionality, you should move away from the
client-side mailto: and change your code to server-side code that
automates Outlook.
But the user is on the client side, how can serve-side automation help?

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]


Scott M. said:
Let me clarify...

The mailto: protocol of a link does not specify that Outlook should open.
It specifies that the browser should open *whatever* email program the
browser has its default set to. Even if Outlook is that program, you may
notice that when you click the link a new mail message is created by
Outlook itself does not open. Because of this order, the signature won't
be added.

If you absolutely need this functionality, you should move away from the
client-side mailto: and change your code to server-side code that
automates Outlook.
 
E

Eliyahu Goldin

In other words, you suggest the user will store the signature on the server
and pay for this by not being able to use his Outlook.

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]


Scott M. said:
The mail message does not have to originate at the client. Whoever said
it had to? The application could provide a web based form for the user to
fill out and when the user is done, that client-data can be used to
populate a server generated mail message.

From the way the OP was written, it seems that just one particular
signature is needed on the outbound message.

Eliyahu Goldin said:
If you absolutely need this functionality, you should move away from the
client-side mailto: and change your code to server-side code that
automates Outlook.
But the user is on the client side, how can serve-side automation help?

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]


Scott M. said:
Let me clarify...

The mailto: protocol of a link does not specify that Outlook should
open. It specifies that the browser should open *whatever* email program
the browser has its default set to. Even if Outlook is that program,
you may notice that when you click the link a new mail message is
created by Outlook itself does not open. Because of this order, the
signature won't be added.

If you absolutely need this functionality, you should move away from the
client-side mailto: and change your code to server-side code that
automates Outlook.


You can't.




Wondering if you can help me.

I am using mailto in a URL. Basically I want the URL to open
outlook --
this is working fine. However I want the email created to include my
outlook
signature, but when I use mailto I get a blank email even though I
have
signatures turned on. Any ideas on how I can get the signature into
the email.

Thanks
 
S

Scott M.

No, I am not quite saying that. I am saying that it seems like the OP wants
a specific signature to be used in all cases by his app (in outher words not
a "user" signature, but an "application" signature). So, using server-side
code to retrieve this signature (yes, stored on the server) and generate and
send the email could accomplish this.

If I am wrong and the OP wants individual users to be able to automatically
get their (different) Outlook signatures attached to different messages,
then my original comments (that you can't even count on all users using
Outlook in the first place) apply.


Eliyahu Goldin said:
In other words, you suggest the user will store the signature on the
server and pay for this by not being able to use his Outlook.

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]


Scott M. said:
The mail message does not have to originate at the client. Whoever said
it had to? The application could provide a web based form for the user
to fill out and when the user is done, that client-data can be used to
populate a server generated mail message.

From the way the OP was written, it seems that just one particular
signature is needed on the outbound message.

Eliyahu Goldin said:
If you absolutely need this functionality, you should move away from
the client-side mailto: and change your code to server-side code that
automates Outlook.
But the user is on the client side, how can serve-side automation help?

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]


Let me clarify...

The mailto: protocol of a link does not specify that Outlook should
open. It specifies that the browser should open *whatever* email
program the browser has its default set to. Even if Outlook is that
program, you may notice that when you click the link a new mail message
is created by Outlook itself does not open. Because of this order, the
signature won't be added.

If you absolutely need this functionality, you should move away from
the client-side mailto: and change your code to server-side code that
automates Outlook.


You can't.




Wondering if you can help me.

I am using mailto in a URL. Basically I want the URL to open
outlook --
this is working fine. However I want the email created to include my
outlook
signature, but when I use mailto I get a blank email even though I
have
signatures turned on. Any ideas on how I can get the signature into
the email.

Thanks
 
E

Eliyahu Goldin

You say it yourself. The server code will be the one who will generate and
send email, not the client-side Outlook. So the user will not be able to use
his familiar Outlook, rather he will have to rely on what the server-side
program provides.

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]


Scott M. said:
No, I am not quite saying that. I am saying that it seems like the OP
wants a specific signature to be used in all cases by his app (in outher
words not a "user" signature, but an "application" signature). So, using
server-side code to retrieve this signature (yes, stored on the server)
and generate and send the email could accomplish this.

If I am wrong and the OP wants individual users to be able to
automatically get their (different) Outlook signatures attached to
different messages, then my original comments (that you can't even count
on all users using Outlook in the first place) apply.


Eliyahu Goldin said:
In other words, you suggest the user will store the signature on the
server and pay for this by not being able to use his Outlook.

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]


Scott M. said:
The mail message does not have to originate at the client. Whoever said
it had to? The application could provide a web based form for the user
to fill out and when the user is done, that client-data can be used to
populate a server generated mail message.

From the way the OP was written, it seems that just one particular
signature is needed on the outbound message.

message If you absolutely need this functionality, you should move away from
the client-side mailto: and change your code to server-side code that
automates Outlook.
But the user is on the client side, how can serve-side automation help?

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]


Let me clarify...

The mailto: protocol of a link does not specify that Outlook should
open. It specifies that the browser should open *whatever* email
program the browser has its default set to. Even if Outlook is that
program, you may notice that when you click the link a new mail
message is created by Outlook itself does not open. Because of this
order, the signature won't be added.

If you absolutely need this functionality, you should move away from
the client-side mailto: and change your code to server-side code that
automates Outlook.


You can't.




Wondering if you can help me.

I am using mailto in a URL. Basically I want the URL to open
outlook --
this is working fine. However I want the email created to include
my outlook
signature, but when I use mailto I get a blank email even though I
have
signatures turned on. Any ideas on how I can get the signature into
the email.

Thanks
 
S

Scott M.

Yes. But as I said, it seems as if the OP wants a specific signature and I
said that the server would be the only way to generate that.


Eliyahu Goldin said:
You say it yourself. The server code will be the one who will generate and
send email, not the client-side Outlook. So the user will not be able to
use his familiar Outlook, rather he will have to rely on what the
server-side program provides.

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]


Scott M. said:
No, I am not quite saying that. I am saying that it seems like the OP
wants a specific signature to be used in all cases by his app (in outher
words not a "user" signature, but an "application" signature). So, using
server-side code to retrieve this signature (yes, stored on the server)
and generate and send the email could accomplish this.

If I am wrong and the OP wants individual users to be able to
automatically get their (different) Outlook signatures attached to
different messages, then my original comments (that you can't even count
on all users using Outlook in the first place) apply.


Eliyahu Goldin said:
In other words, you suggest the user will store the signature on the
server and pay for this by not being able to use his Outlook.

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]


The mail message does not have to originate at the client. Whoever
said it had to? The application could provide a web based form for the
user to fill out and when the user is done, that client-data can be
used to populate a server generated mail message.

From the way the OP was written, it seems that just one particular
signature is needed on the outbound message.

message If you absolutely need this functionality, you should move away from
the client-side mailto: and change your code to server-side code that
automates Outlook.
But the user is on the client side, how can serve-side automation
help?

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]


Let me clarify...

The mailto: protocol of a link does not specify that Outlook should
open. It specifies that the browser should open *whatever* email
program the browser has its default set to. Even if Outlook is that
program, you may notice that when you click the link a new mail
message is created by Outlook itself does not open. Because of this
order, the signature won't be added.

If you absolutely need this functionality, you should move away from
the client-side mailto: and change your code to server-side code that
automates Outlook.


You can't.




Wondering if you can help me.

I am using mailto in a URL. Basically I want the URL to open
outlook --
this is working fine. However I want the email created to include
my outlook
signature, but when I use mailto I get a blank email even though I
have
signatures turned on. Any ideas on how I can get the signature into
the email.

Thanks
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Staff online

Members online

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,816
Latest member
SapanaCarpetStudio

Latest Threads

Top