2016-09-28 103 views
0

我指的是datepicker的這個站點http://jqueryui.com/datepicker/,我的編碼與給出的源代碼非常相似。這些編碼工作正常。當添加runat =「server」時Datepicker不工作

但是...

當我加入RUNAT =「服務器」這段代碼<input type="text" id="datepicker">點擊TextBox當我的日曆不會出現內部。我需要把runat =「server」,這樣我才能夠在後面的代碼中使用它。

任何建議從你們將不勝感激。謝謝。

+0

諮詢您的控制檯是否存在錯誤 – madalinivascu

+1

您無法直接在代碼後面獲取js組件。看這裏 http://stackoverflow.com/questions/9032068/how-to-set-a-date-get-a-date-for-datepicker-in-codebehind – Den

回答

0

我找到了正確的方式做到這一點。

對於ASP.Net設計

<asp:TextBox runat="server" id="datepicker"></asp:TextBox>

在客戶端服務器端

$(document).ready(function() { $("[id$=datepicker]").datepicker(); });

$("[id$=datepicker]").datepicker();,而不是$('#<%= datepicker.ClientID %>').datepicker();則日曆將顯示並可以調用日期選擇器後面的代碼。

1

RUNAT =服務器與母版頁添加則產生與母版頁默認樣式ID ..因此,爲了避免它嘗試的ClientIDMode =「靜態」

<input type="text" id="datepicker" runat="server" ClientIDMode="Static"> 

用出來的ClientIDMode = 「靜態」生成的HTML是

<input type="text" id="MainContent_datepicker" name="ctl00$MainContent$datepicker"> 

更多信息使用firebug Mozilla Firefox的由檢查元素使用f irebug

0

當視圖源中的文本框爲runat =「server」時,您可以找到生成具有動態前綴的文本框的名稱。

所以在你的JavaScript中,你不應該使用標籤中指定的id屬性,而應該使用<%= IdAttributeValue.ClientID%>,它會給出生成的ID。

0

嘗試使用此

<script> 
$(document).ready(function() { 
$("body").delegate("#<%=datepicker.ClientID%>", "focusin", function() { 
$(this).datepicker(); 
}); 
}); 
    </script>