如何使用jquery获得DataList控件的clientID的 [英] How to get clientID of Datalist control using jquery

查看:170
本文介绍了如何使用jquery获得DataList控件的clientID的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用jQuery获得DataList控件的客户端ID,我尝试使用下面的code,无更迭:

How to get clientID of Datalist control using jquery , I tried using the code below with no succes:

$(document).ready(function(){
$('#<%=txtRenewalDate.ClientID %>').datepicker();
    $('#<%=txtCallBackDate.ClientID %>').datepicker();

});
<asp:DataList ID="dlCustomers" runat="server" ClientIDMode="Predictable">
    <ItemTemplate>
      <table border="0">
                    <tr>
                        <td class="">
                            RenewalDate:
                        </td>
                        <td class="">
                            <asp:TextBox ID="txtRenewalDate" runat="server" Text='<%# Eval("RenewalDate") %>' ClientIDMode="Static"></asp:TextBox>
                        </td>
                    </tr>
                    <tr>
                        <td class="">
                            Callback
                        </td>
                        <td class="">
                            <asp:TextBox ID="txtCallBackDate" runat="server" Text='<%# Eval("Callback") %>' ClientIDMode="Static"></asp:TextBox>
                        </td>
                    </tr></table>
                     </ItemTemplate>
</asp:DataList>

当脚本注释标记
    

Markup when script is commented

                        <td class="">

                            RenewalDate:

                        </td>

                        <td class="">

                            <input name="ctl00$MainContent$dlCustomers$ctl00$txtRenewalDate" type="text" value="27/01/2012 00:00:00" id="txtRenewalDate" />

                        </td>

                    </tr>

                    <tr>

                        <td class="">

                            Callback

                        </td>

                        <td class="">

                            <input name="ctl00$MainContent$dlCustomers$ctl00$txtCallBackDate" type="text" value="27/01/2012 00:00:00" id="txtCallBackDate" />

                        </td>

                    </tr>

我收到以下错误,当我运行:
txtRenewalDate'这个名字并不在目前的情况下存在
txtCallBackDate'这个名字并不在当前的背景下存在

I get the following errors when i run : The name 'txtRenewalDate' does not exist in the current context The name 'txtCallBackDate' does not exist in the current context

任何想法,我得到它错了。

Any ideas where i am getting it wrong .

感谢

推荐答案

我认为这个问题可能是因为这些控件是在DataList中,你是从DataList控件之外打电话给他们,他们在技术上并不在根目录中的形式。你可能需要做这样的事情:

I think that the issue may be that since those controls are within the datalist and you are calling them from outside of the datalist they technically do not exist at the root of the form. You may need to do something like this:

 $('#<%= dlCustomers.FindControl("txtRenewalDate").ClientID %>')

我可能是错的,但是这是我最好的猜测。

I may be wrong but that is my best guess.

这篇关于如何使用jquery获得DataList控件的clientID的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆