1

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".

Community
  • 1
  • 1

1 Answers1

1

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!

deebs
  • 1,390
  • 10
  • 23
  • 1
    I tried that same quote combination but it didn't work. I'll try the SendEmail. Thanks! – Matt Bergevin Jun 27 '14 at 13:41
  • I made and edit to clarify the change. I can test now as well to check – deebs Jun 27 '14 at 15:41
  • Further edit, which is now tested. Got help from this thread: http://stackoverflow.com/questions/249926/passing-eval-from-aspx-to-javascript-function-as-parameter – deebs Jun 27 '14 at 17:50