1

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

3 Answers 3

7

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>
Sign up to request clarification or add additional context in comments.

3 Comments

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?
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).
Yes, that worked! I will post my answer. Thank you very much!!
1

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.

Comments

0

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>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.