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

Discussion in 'ASP .Net' started by mark4asp, Nov 6, 2006.

  1. mark4asp

    mark4asp Guest

    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.
     
    mark4asp, Nov 6, 2006
    #1
    1. Advertising

  2. mark4asp

    Superman Guest

    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!

    mark4asp wrote:
    > 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.
     
    Superman, Nov 6, 2006
    #2
    1. Advertising

  3. mark4asp

    Harry Haller Guest

    On 6 Nov 2006 11:33:43 -0800, "Superman" <> wrote:

    >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")) %>' />
     
    Harry Haller, Nov 7, 2006
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. shruds
    Replies:
    1
    Views:
    834
    John C. Bollinger
    Jan 27, 2006
  2. Replies:
    1
    Views:
    388
    Andrew Thompson
    Nov 29, 2006
  3. Andreas Bogenberger
    Replies:
    3
    Views:
    931
    Andreas Bogenberger
    Feb 22, 2008
  4. afrinspray
    Replies:
    2
    Views:
    135
    afrinspray
    Sep 7, 2006
  5. dkl1
    Replies:
    2
    Views:
    192
Loading...

Share This Page