将Eval参数从ASPX文件传递给JavaScript函数

问题描述 投票:6回答:2

我尝试像这样传递Eval值但得到语法错误:

<asp:ImageButton ID="btnOK" OnClientClick='Show("<%#Eval("Title")%>");return false;'  runat="server" ImageUrl="Images/icon.gif" />      
asp.net
2个回答
8
投票

试试这个。

<asp:ImageButton ID="btnOK" OnClientClick='<%# Eval("Title", "Show({0});return false;") %>' runat="server" ImageUrl="Images/icon.gif" />

1
投票
OnClientClick='<%#String.Format("Show('{0}');return false;",Eval("title"))%>'

或者如果在设计视图中执行此操作,只需为imagebutton的onClientClick属性添加数据绑定即可

String.Format("Show('{0}');return false;",Eval("title"))

希望它能帮助你。

© www.soinside.com 2019 - 2024. All rights reserved.