2017-05-12 34 views
0

イメージボタンonClientClickイベントの新しいウィンドウにPDFファイルを開こうとしていますが、画像ボタンをクリックすると何も起こりません。また、2回目にクリックすると新しいウィンドウにファイルが開きます 最初のクリックでファイルを開くだけですOnClientClickが動作していません初めての場合

私は以下のコードを使用しました。

//Find control in Grid view 
GridViewRow row = (GridViewRow (((ImageButton)e.CommandSource).NamingContainer); 
HiddenField hdnFileName = (HiddenField)row.FindControl("hdnFilePath"); 
ImageButton ibtn = (ImageButton)row.FindControl("ibtnDownload"); 

//Get File Path and FileName and Concate 
string strFilePath = "\\OnlineContent\\"; 
string filePath = strFilePath +"/"+ hdnFileName.Value; 

//Open PDF file into new tab 
ibtn.OnClientClick = "window.open('"+filePath.ToString()+"','target=_blank');"; 
+0

文字列変数filePathが "\\ OnlineContent \\/{value}"で初期化されていることにご注意ください。 –

+0

'window.open'を使うことは常に悪い考えです。多くのブラウザ/プラグイン/ウィルススキャナがそれをブロックできます。 – VDWWD

+0

はい私は@ MasterYodaを知っています – WeeZy

答えて

1

\ OnlineContentの前に。(ダブルドット)または〜(チルダ記号)を使用します。

文字列strFilePath = "\ OnlineContent \"; 文字列filePath = strFilePath + "/" + hdnFileName.Value;

関連する問題