开发者

ASP.NET MVC: replace <%= Html.TextBox("name") %> with <asp:TextBox>

开发者 https://www.devze.com 2022-12-15 06:38 出处:网络
Because i want to set a Extender (Calendar from the AJAX Controls toolkit) on a textbox, I have to change the code from

Because i want to set a Extender (Calendar from the AJAX Controls toolkit) on a textbox, I have to change the code from

<%= Html.TextBo开发者_运维技巧x("name") %> 

to

<asp:TextBox ...>

But how can i bind the attribute "name" on the element?

Thank you


Have you tried using the jQuery DatePicker? It's much more friendly with MVC than the standard ASP controls and related extenders.

<%= Html.TextBox( "name" ) %>

<script type="text/javascript">
    $(function() {
       $('[name=name]').datepicker();
    });
</script>


It's possible to use the asp.net Ajax Beta to create a client side Calendar.

See here: http://www.asp.net/ajaxlibrary/HOW%20TO%20Use%20the%20Calendar%20Control.ashx

Strangely this version of the asp.net ajax library uses JQuery as well.

I would personally use the JQuery version... But the new asp.net ajax library is trying to evolve so that it works better with 'pure' html and asp.net mvc.


Ok,

I included the js from the google api, also the css.

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/jquery-ui.min.js"></script>
<link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/themes/overcast/jquery-ui.css" type="text/css" rel="Stylesheet" class="ui-theme" />

Then set the datepicker like this:

<script type="text/javascript">
$(document).ready(function() {
$("#startDate").datepicker();
});
</script>
0

精彩评论

暂无评论...
验证码 换一张
取 消