C# 使用OnClientClick-ASP.Net打开新页面

C# 使用OnClientClick-ASP.Net打开新页面,c#,asp.net,.net,C#,Asp.net,.net,我在ASP.NETC#工作。单击按钮(添加到gridview中)时,尝试调用Downlaod.aspx页面下载文件。下面是代码 <asp:Button ID="btnViewDocument" runat="server" Text="View" UseSubmitBehavior="False" OnClientClick='<%# String.Format("window.open(""../../Views/Common/Download.aspx?PropertyD

我在ASP.NETC#工作。单击按钮(添加到gridview中)时,尝试调用Downlaod.aspx页面下载文件。下面是代码

<asp:Button ID="btnViewDocument" runat="server" Text="View" UseSubmitBehavior="False"
    OnClientClick='<%# String.Format("window.open(""../../Views/Common/Download.aspx?PropertyDocumentID={0}""); return false;", Eval("DocumentId").ToString())%>' />

当我单击它时,我可以在浏览器控制台中看到以下错误

未捕获的语法错误:意外标记


但我无法找出语法错误。

一个选项是创建一个单独的js函数,并按如下方式使用它:

<asp:Button ID="btnViewDocument" runat="server" Text="View" UseSubmitBehavior="False" OnClientClick='OpenWindow(<%# Eval("DocumentId").ToString() %>)' />

一种选择是创建一个单独的js函数,并按如下方式使用它:

<asp:Button ID="btnViewDocument" runat="server" Text="View" UseSubmitBehavior="False" OnClientClick='OpenWindow(<%# Eval("DocumentId").ToString() %>)' />
请尝试以下内容:

方法1:

将双引号更改为单引号

<asp:Button ID="btnViewDocument" runat="server" Text="View" UseSubmitBehavior="False" OnClientClick = '<%#String.Format("window.open('../../Views/Common/Download.aspx?PropertyDocumentID={0}'); return false;');",Eval("DocumentId").ToString()) %>' />
方法2:

HTML

<asp:Button ID="btnViewDocument" runat="server" Text="View" UseSubmitBehavior="False" OnClientClick='<%# "LocateMyPage(" + Eval("DocumentId").ToString() + ");" %>' />

Javascript

<script type="text/javascript">

 function LocateMyPage(DocID){
     window.open('../../Views/Common/Download.aspx?PropertyDocumentID=' + DocID);
     return false;
 }

</script>

函数LocateMyPage(DocID){
window.open('../../Views/Common/Download.aspx?PropertyDocumentID='+DocID);
返回false;
}
尝试以下操作:

方法1:

将双引号更改为单引号

<asp:Button ID="btnViewDocument" runat="server" Text="View" UseSubmitBehavior="False" OnClientClick = '<%#String.Format("window.open('../../Views/Common/Download.aspx?PropertyDocumentID={0}'); return false;');",Eval("DocumentId").ToString()) %>' />
方法2:

HTML

<asp:Button ID="btnViewDocument" runat="server" Text="View" UseSubmitBehavior="False" OnClientClick='<%# "LocateMyPage(" + Eval("DocumentId").ToString() + ");" %>' />

Javascript

<script type="text/javascript">

 function LocateMyPage(DocID){
     window.open('../../Views/Common/Download.aspx?PropertyDocumentID=' + DocID);
     return false;
 }

</script>

函数LocateMyPage(DocID){
window.open('../../Views/Common/Download.aspx?PropertyDocumentID='+DocID);
返回false;
}