How do I include a server tag within a javascript parameter which is itself within a HTML element ev

M

mark4asp

How do I include a server tag within a javascript parameter which is
itself within a HTML element event.

For instance no matter what permutation of quotes I try here I get
errors on this line:

<asp:ImageButton ID="cmdDeleteLogin" runat="server"
SkinID="DeleteButton" CommandName="DeleteLogin"
CommandArgument='<%# Eval("LoginID") %>'
OnClientClick =
'return confirm(Are you certain you want to delete: <%#
Eval("UserName") %>)' />

I want the final code to look something like this:

<input type="image"
name="ctl00$ContentPlaceHolder$repLogins$ctl01$cmdEditLogin"
id="ctl00_ContentPlaceHolder_repLogins_ctl01_cmdEditLogin"
src="../App_Themes/SomeSite_Admin/images/edit_button.gif"
onclick="return confirm('Are you certain you want to delete: Joe
Doe');"
style="border-width:0px;" />

Clearly the problem is that double quotes can't be used to enclose <%#
Eval("UserName") %> but I need to enclose the argument to the
javascript confirm function in qutoes.

I found out what the problem was here
<http://blogs.clearscreen.com/ragc/archive/2004/10/28/525.aspx> but
there's no clue as to what the solution might be.
 
S

Superman

Mark,

At first glance it looks like you're missing some single quotes (or
quotes around your confirm() call. The text is not wrapped!

If that doesn't yeild any results, this is how I do these types of
things:

OnClientClick ='<%# String.format("return confirm('Are you certain you
want to delete: {0} ?'", Eval("UserName"))%>' />


Good luck!
 
H

Harry Haller

Mark,

At first glance it looks like you're missing some single quotes (or
quotes around your confirm() call. The text is not wrapped!

If that doesn't yeild any results, this is how I do these types of
things:

OnClientClick ='<%# String.format("return confirm('Are you certain you
want to delete: {0} ?'", Eval("UserName"))%>' />

Thanks, I added a couple of bits which I thought should make it work
but they don't. I still ... I still get that error "server tag is not
well-formed". It's a mystery to me.

<asp:ImageButton ID="cmdDeleteLogin" runat="server"
SkinID="DeleteButton" CommandName="DeleteLogin"
CommandArgument='<%# Eval("LoginID") %>'
OnClientClick ='<%# System.String.Format("return confirm('Are you
certain you want to delete: {0} ?')", Eval("UserName")) %>' />
 

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

Members online

Forum statistics

Threads
473,731
Messages
2,569,432
Members
44,835
Latest member
KetoRushACVBuy

Latest Threads

Top