【发布时间】:2009-09-21 15:58:58
【问题描述】:
尝试从 asp:gridview 数据行中使用 Jquery 弹出一个 IFrame Shadowbox。我无法在字符串中得到正确的引号:
<asp:ImageButton ID="btnEdit" runat="server"
OnClientClick='<%# "javascript:popAccount(\'"+
Eval("id", "Popup.aspx?id={0}")+"\');" %>' />
解析器错误消息:服务器标签格式不正确。
没有转义的单引号(不能工作,但可以正确解析):
<asp:ImageButton ID="btnEdit" runat="server"
OnClientClick='<%# "javascript:popAccount("+
Eval("id", "Popup.aspx?id={0}")+");" %>' />
客户端 HTML,正如预期的那样:
onclick="javascript:popAccount(Popup.aspx?id=3ce3b19c-1899-4e1c-b3ce-55e5c02f1);"
如何在 Javascript 中获取引号?
编辑:添加解决方案。这不是很通用,因为必须知道数据绑定类型才能访问 id 属性。键(在 GrodView 的 DataKeyNames 参数中定义)似乎没有在事件参数中公开。但它有效。
protected void editGrid_RowDataBound(object sender, GridViewRowEventArgs e)
{
// do not look at header or footer
if (e.Row.RowType == DataControlRowType.DataRow)
{
ImageButton btn = e.Row.FindControl("btnPopup") as ImageButton;
if (btn != null)
{
btn.OnClientClick =
"javascript:popAccount('EditAccountPopup.aspx?"+
Constants.acctidParam+"="+
((tb_account)(e.Row.DataItem)).id.ToString()+"');";
}
}
【问题讨论】:
标签: asp.net javascript data-binding