2013-07-26 141 views
0

我想從一個按鈕調用一個函數,但是當我按下按鈕時,它說沒有聲明該名稱的任何函數。函數尚未聲明

這是我對按鈕的代碼:

<asp:TextBox ID="DateOutTxt" runat="server" Width="80px"></asp:TextBox><asp:ImageButton 
        ID="ImageButton5" runat="server" BorderStyle="None" ImageUrl="~/icons/vwicn063.gif" 
        OnClientClick="PopupPicker(DateOutTxt, 250, 250);" Width="21px" /></td> 

,這裏是我試圖調用的函數:

<script language ="javascript" type ="text/javascript"> 
    function PopupPicker(ctl, w, h) { 
     var PopupWindow = null; 
     settings = 'width=' + w + ',height=' + h + ',location=no,directories=no, menubar=no,toolbar=no,status=no,scrollbars=no,resizable=no,dependent=no'; 
     PopupWindow = window.open(<%= getServerName.getserverName("/Quoteman/DatePicker.aspx?Ctl=") %>); 
    PopupWindow.focus(); 
} 
</script> 

我現在有在標籤底部的腳本標籤,但我已經嘗試將它放在標籤和標籤下面。我似乎無法找到問題。

語言是ASP.Net和Javascript。那裏還有一個VB.Net函數的調用。

回答

0

確保腳本的可用性,將腳本放在head標籤或befor html元素中。你逝去的當前對象以錯誤的方式,在報價中window.open使用的,而不是DateOutTxt

變化

OnClientClick="PopupPicker(DateOutTxt, 250, 250);" 

OnClientClick="PopupPicker(this, 250, 250);" 

戴上小腳本。

function PopupPicker(ctl, w, h) { 
    var PopupWindow = null; 
    settings = 'width=' + w + ',height=' + h + ',location=no,directories=no, menubar=no,toolbar=no,status=no,scrollbars=no,resizable=no,dependent=no'; 
    PopupWindow = window.open('<%= getServerName.getserverName("/Quoteman/DatePicker.aspx?Ctl=") %>'); 
    PopupWindow.focus(); 
} 
+0

我仍然收到錯誤消息「的Javascript運行時錯誤:PopupPicker未定義 – GeoffWilson

+0

檢查我的更新答案,並從PopupPicker所有代碼,並把警報(‘’);確保我們可以打電話給它。 – Adil

+0

你可以用螢火蟲調用這個函數嗎? – Christian