ASP.net和JQuery UI日期选择 [英] ASP.net and JQuery UI Datepicker

查看:349
本文介绍了ASP.net和JQuery UI日期选择的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设:

<input id="datepicker" type="text" />

其中ID =日期选择器告诉JavaScript来所有的日期选择器code附加到表单元素,我怎么把它变成一个服务器控件?

Where the id = datepicker tells the javascript to attach all the datepicker code to the form element, how do I turn this into a server control?

例如:

<input runat="server" id="datepicker" type="text" />

不起作用,因为ASP.net产生它自己的ID。

Doesn't work because ASP.net generates it's own ID's.

修改

<asp:TextBox runat="server" ID="dateTo" class="datepicker"></asp:TextBox>

呈现为

<input name="ctl00$mainContent$dateTo" type="text" id="ctl00_mainContent_dateTo" class="datepicker" />

和不起作用!

推荐答案

我认为这是一个很好的做法,有一个类触发为有它的一切要创建的日期选择器,如JS-日期选择器

I think it's a good practice to have a class which triggers a date picker to be created for everything that has it, such as 'js-date-picker'

然后避免code的重复,你可以只写以下一次JS:

then to avoid duplication of code, you can just write the following JS once:

$(document).ready(function() { 
    $(".js-date-picker").datepicker();
});

让ASP.net正确设置类的文本框,因此使用这个类,只需添加的CssClass =JS-日期选择器来标记:

to get ASP.net to set a class on the textbox correctly so it uses this class, just add CssClass="js-date-picker" to the tag:

<asp:TextBox runat="server" ID="dateTo" CssClass="js-date-picker" />

希望这澄清事情你。

Hope this clarifies things for you.

这篇关于ASP.net和JQuery UI日期选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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