最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

c# - passing eval to javascript - Stack Overflow

programmeradmin4浏览0评论

I am trying to pass this eval to javascript but keep on getting the following error:

<input type="submit" value="Send" id="btnPDf" onclick='<%# "openLink( " +   Eval("ID" )  +  "  );" %>' runat="server" />

the error in firebug:

Timestamp: 12/11/2012 17:59:16
Error: SyntaxError: identifier starts immediately after numeric literal
Line: 1, Column: 24
Source Code:
openLink( b690d0c5-9269-424a-ac57-02f3359c982f );

I have tried passing it with double quotes and back slashes like '\' but still no joy

I am trying to pass this eval to javascript but keep on getting the following error:

<input type="submit" value="Send" id="btnPDf" onclick='<%# "openLink( " +   Eval("ID" )  +  "  );" %>' runat="server" />

the error in firebug:

Timestamp: 12/11/2012 17:59:16
Error: SyntaxError: identifier starts immediately after numeric literal
Line: 1, Column: 24
Source Code:
openLink( b690d0c5-9269-424a-ac57-02f3359c982f );

I have tried passing it with double quotes and back slashes like '\' but still no joy

Share Improve this question asked Nov 12, 2012 at 18:00 ZakiZaki 5,6007 gold badges58 silver badges91 bronze badges 5
  • "I have tried passing it with double quotes" - was it like this: onclick='<%# "openLink(\"" + Eval("ID" ) + "\" );" %>'? – Viktor S. Commented Nov 12, 2012 at 18:03
  • 1 You're showing us the "pre-rendered" code and the "post-rendered" error... can you show us the "post-rendered" code? (I.e. the code the browser has received? – freefaller Commented Nov 12, 2012 at 18:03
  • @freefaller This, openLink( b690d0c5-9269-424a-ac57-02f3359c982f );, sounds like post-render code ) – Viktor S. Commented Nov 12, 2012 at 18:04
  • Not sure if this helps, but you should be able to do this: onclick='<%# Eval("ID", "openLink(\"{0}\");") %>' – Shmiddty Commented Nov 12, 2012 at 18:05
  • Issue #1, JavaScript does not belong in inline attributes. Issue #2, using another language to build JavaScript is a bad idea. Issue #3, you forgot to quote the Eval("ID") value. – zzzzBov Commented Nov 12, 2012 at 18:06
Add a ment  | 

1 Answer 1

Reset to default 9

Your string concatenation is broken. You need to wrap your parameter in quotes using escape sequences -

onclick='<%# "openLink(\"" + Eval("ID" ) + "\" );" %>'
发布评论

评论列表(0)

  1. 暂无评论