Michael Bavin
Michael Bavin

Reputation: 4014

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

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

Upvotes: 1

Views: 1115

Answers (3)

dtc
dtc

Reputation: 10296

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.

Upvotes: 1

Michael Bavin
Michael Bavin

Reputation: 4014

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>

Upvotes: 0

tvanfosson
tvanfosson

Reputation: 532725

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>

Upvotes: 7

Related Questions