This one has been giving me trouble all morning and I hope someone with more ASP knowledge can help me! I didn't build this app, I inherited it and it was built in .NET 2.0.
I'm upgrading an app that generated a list of href=mailto. Now it needs to run some C# code so I started recreating these as linkButtons. I was following this article How to launching email client on LinkButton click event? but I have one more step.
<asp:Repeater DataSourceID="sdsUserList" runat="server">
<ItemTemplate>
<li>
<asp:LinkButton ID="lbEmail" runat="server" Text='<%# Eval("UserName") %>' OnClientClick="window.open('mailto:<%# Eval("UserEmail") %>', 'email')" OnClick="lblEmail_Click" />
</li>
</ItemTemplate>
</asp:Repeater>
I need the OnClientClick to simply open up a new email to send to the User. I've monkeyed around with the quotes but the error I am getting is "The server tag is not well formed".
It could be the quotes for your OnClientClick. You'll need to change this:
OnClientClick="window.open('mailto:<%# Eval("UserEmail") %>', 'email')"
You could try calling a function with the Eval statement as a parameter. For example:
OnClientClick='<%# String.Format("javascript:return SendEmail(\"{0}\")", Eval("UserEmail").ToString()) %>'
<script type="text/javascript">
function SendEmail(email){
window.open("mailto:" + email);
}
</script>
I think there are other ways to escape the quotes too, but that's just a possible quick fix. This I just tested and it works fine. Good luck!
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments