views:

423

answers:

3

Hello,

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

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

to

<asp:TextBox ...>

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

Thank you

+7  A: 

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>
tvanfosson
Thanks, but it doesn't work, I have this:<%= Html.TextBox("startDate") %> <script type="text/javascript"> $(function() { $('#startDate').datepicker(); }); </script> I have standard jquery .js files in the Scripts folder. Any suggestion?
Michael Bavin
It's a jQuery UI widget. You'll need to include at least jQuery UI core and the datepicker, if not all of the jQuery UI code (and CSS).
tvanfosson
Yes, that worked! I will post my answer. Thank you very much!!
Michael Bavin
A: 

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"&gt;&lt;/script&gt;
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/jquery-ui.min.js"&gt;&lt;/script&gt;
<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>
Michael Bavin
+1  A: 

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.

metanaito