沒有得到的ClientID我有ASP.Net頁我在哪裏調用JavaScript函數如下:在ASP.Net
Enter server name: <asp:TextBox ID="txt_name" runat="server"></asp:TextBox>
<asp:Button ID="btn_view" runat="server" OnClick="View_btn_click" OnClientClick="return AlertOnGo('View Configuration',document.getElementById('<%= txt_name.ClientID %>').value)" Text ="GO!" />
但在點擊GO按鈕,我收到以下錯誤:
的JavaScript運行時錯誤:無法獲取的未定義或空引用
屬性「價值」上觀看所呈現的代碼的按鈕:
<input type="submit" name="btn_view" value="GO!" onclick="return AlertOnGo('View Configuration',document.getElementById('<%= txt_name.ClientID %>').value);" id="btn_view" />
它沒有放置適當的ClientID。我試着將CLientIDMode設置爲靜態的測試框,但沒有幫助。
此問題與unanswered question類似。
我認爲這發生,因爲當你呈現你的ASP。網絡文本框控件,他是一個不同的id,而不是你在編輯html時看到的內容。 – 2013-04-22 12:42:24
看看這是否可以幫助你,http://stackoverflow.com/questions/8844675/asp-net-document-getelementbyid-control- clientid-returns-null – 2013-04-22 12:43:30