积极答复者
请教控件的OnClientClick属性的正确写法以及原因

问题
-
function DeleteConfirm(info) { return window.confirm("是否删除数据:" + info); //点击删除按钮时出现确定窗口 }
js处的代码如上,我把它加到按钮的OnClientClick
OnClientClick="return DeleteConfirm(<%#Eval("建筑名称")%>)"
系统说无法解析
OnClientClick="return DeleteConfirm('<%#Eval("建筑名称")%>')"
系统还是无法解析
OnClientClick=<%#"return DeleteConfirm('" + Eval("建筑名称")+"')"%>
查网上发现这种终于能解析了,但是VS又说我属性值没加引号。但是倒不影响运行
OnClientClick="<%#"return DeleteConfirm('" + Eval("建筑名称")+"')"%>"
于是又改成这样,vs不报错了,但是一运行又不能解析了。
这个html的双单引号用法这么奇怪吗,怎么写才是正确的。以及原因是什么
- 已编辑 终于出名 2012年11月16日 0:46
答案
-
你好,
请参考以下代码:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="test8.aspx.cs" Inherits="test8" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> <script type="text/javascript"> function DeleteConfirm(info) { window.confirm("是否删除数据:" + info); //点击删除按钮时出现确定窗口 } var t = "<%=ReadyMaterials%>"; </script> </head> <body> <form id="form1" runat="server"> <asp:Button ID="Button1" runat="server" Text="Button" OnClientClick="DeleteConfirm(t)" /> </form> </body> </html>
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; public partial class test8 : System.Web.UI.Page { protected string ReadyMaterials = "Product"; protected void Page_Load(object sender, EventArgs e) { } }
Please mark the replies as answers if they help or unmark if not.
If you have any feedback about my replies, please contact msdnmg@microsoft.com
Microsoft One Code Framework- 已标记为答案 Song TianModerator 2012年11月22日 14:33
全部回复
-
你好,
请参考以下代码:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="test8.aspx.cs" Inherits="test8" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> <script type="text/javascript"> function DeleteConfirm(info) { window.confirm("是否删除数据:" + info); //点击删除按钮时出现确定窗口 } var t = "<%=ReadyMaterials%>"; </script> </head> <body> <form id="form1" runat="server"> <asp:Button ID="Button1" runat="server" Text="Button" OnClientClick="DeleteConfirm(t)" /> </form> </body> </html>
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; public partial class test8 : System.Web.UI.Page { protected string ReadyMaterials = "Product"; protected void Page_Load(object sender, EventArgs e) { } }
Please mark the replies as answers if they help or unmark if not.
If you have any feedback about my replies, please contact msdnmg@microsoft.com
Microsoft One Code Framework- 已标记为答案 Song TianModerator 2012年11月22日 14:33
-
改成这个试试:
OnClientClick="return confirm('<%#Eval("建筑名称")%>')"
或者:
OnClientClick="return confirm('确定要删除吗')"
其实没必要带上数据绑定的,不过就是删除按钮点击时候的警告而已。
www.willin.org
- 已建议为答案 Willin Wang 2012年11月19日 11:03