2012-02-20 75 views
1

對不起,我找不到任何答案。我不能讓JQueryUI與ASP.net服務器控件一起工作

這是一個已知的問題?它有解決方案嗎?

請幫忙。我想ASP.net服務器使用jQueryUI的控制

示例腳本

$(document).ready(function() { 
      $('#txtSearch').datepicker({ 
       showPeriod: true, 
       showLeadingZero: true 
      }); 
      $('#Text1').datepicker({ 
       showPeriod: true, 
       showLeadingZero: true 
      }); 
     }); 

樣品標記

<input id="Text1" type="text"/> 
    <asp:TextBox ID="txtSearch" runat="server" Height="21px" Width="196px"> 
    </asp:TextBox> 

的事情是在其工作正常的html控制,但不是在asp控制 我欣賞任何幫助。謝謝!

回答

1

請嘗試以下操作。如果您查看頁面的源代碼,您將看到asp.net控件的ID已動態更改。使用下面的可以訪問該動態地生成的ID爲txtSearch html元素:

$(document).ready(function() { 
      $('#<%=txtSearch.ClientID%>').timepicker({ 
       showPeriod: true, 
       showLeadingZero: true 
      }); 
      $('#Text1').timepicker({ 
       showPeriod: true, 
       showLeadingZero: true 
      }); 
     }); 
+0

的作品就像一個魅力! =) – 2012-02-20 17:31:34

0

當服務器控制呈現,控制的ID被改變。所以你的txtSearch id會變成類似ct001_txtSearch的東西。 這就是jquery無法找到它的原因,因爲它正在尋找id'txtSearch',但沒有使用id'txtSearch'的控件。

嘗試使用clientID來引用該id。

0

快速之一可能是:只使用HTML控件並將其標記爲RUNAT = 「服務器」

居:

<input type="text" id="Textbox1" runat="server"> 
+0

我試過了,它沒有工作 – 2012-02-20 17:29:49

+0

使用像螢火蟲(或簡單地查看html頁面的來源)的工具,並找出什麼是由asp.net爲該控制產生的id。或者只是將一個css類添加到您的控件中,並將jquery日曆綁定到類而不是id。 – 2012-02-20 17:32:12

相關問題