2016-04-19 22 views
1

私はASP.Net C#で作業しています。ボタン(gridviewに追加された)がクリックされたときにファイルをダウンロードするためにDownlaod.aspxページを呼び出そうとしています。以下はコードです。OnClientClick - ASP.Netを使用して新しいページを開く

<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())%>' /> 

私がクリックすると、ブラウザのコンソールで次のエラーが表示されることがあります。

Uncaught SyntaxError: Unexpected token .

しかし、私は構文エラーを理解することができません。

答えて

0

1つのオプションは、別のJS関数を作成し、以下のようにそれを使用することです:

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

JS機能:

function OpenWindow(documentId) 
{ 
    window.open("../../Views/Common/Download.aspx?PropertyDocumentID=" + documentId); 
    return false; 
} 
1

以下は試してみてください。

方法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()) %>' /> 

またはあなたのstring.Formatを削除して、この

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

方法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> 
関連する問題