ASP.NET Calendar OnSelectionChanged handler not getting called -


Can some please tell me why when clicking on a day within the "Calendar" control, "Michaelderseri selection changelog" Is not an event handler being executed? This sample is simple aspx code from the ASP.NET MVC2 application:

  <% @ Page language = "C #" masterpagefile = "~ / view / share / site.masters" inheritance = "System.Web.Mvc.ViewPage"%> & Lt; Script runat = "server" & gt; Private Zero MyCalendar_SelectionChanged (Object Sender, System.EventArgs e) {//lbl1.Text = Calendar1.SelectedDate.ToString (); Console.WriteLine ("test"); } & Lt; / Script & gt; & Lt; Asp: Content ID = "Content1" content placeholder ID = "TitleContent" runat = "server" & gt; Home page & lt; / Asp: Content & gt; & Lt; Asp: Content ID = "Content2" content placeholder id = "main content" run = "server" & gt; & Lt; Form id = "form1" runat = "server" & gt; & Lt; H2 & gt; & Lt;% = HTML.Encode (View Data ["Message"])% & gt; & Lt; / H2 & gt; & Lt; P & gt; To learn more about ASP.NET MVC & lt; A href = "http://asp.net/mvc" title = "ASP.Net MVC website" & gt; Http: //asp.net/mvc< / A & gt; & Lt; / P & gt; & Lt; Div & gt; & Lt; ASP: Calendar ID = "Calendar 1" Runt = "Server" On-Change = "MyCalendar_SelectionChanged" /> & Lt; / Div & gt; & Lt; / Form & gt; & Lt; / ASP: Content & gt;    

and ASP: calendar runat = "server" ... / Gt; is a server control that depends on Winstate and Postback, which are ideas that are no longer present in ASP.NET MVC, so you should not use any server controls. Because there is no postback and your callback will not trigger your function. Also, make sure that you remove runat = "server" tag from your form and use HTML assisters to create forms.

You can checkout to implement a calendar in ASP.NET MVC.

How can you proceed like this:

As usual, you start with M (O) in MVC, which will represent the information you display (your A date in the case):

  public class MyViewModel {public date time date {get; Set; }}   

Then you can get the C in the MVC: the

  public class home controller: controller {// to see the usage Public Action Result Index () {var model = new MyViewModel {Date = DateTime.Now}; See Return (Model); } // When the form is submitted, it will be called [HTPOST] Public ActionRashult Index (MyView Model Model) {Return View (Model); }}   

then V (iew) in MVC:

  & lt;% @ page language = "c #" masterpage file = "~ / View / Share / Site. Mister "Inherits =" System.View Web.mvc page & lt; AppName.Models.MyViewModel & gt; "& Gt%; & Lt; Asp: Content ID = "Content2" content placeholder id = "main content" run = "server" & gt; Use of & lt;% (Html.BeginForm ()) {%> & Lt;% = Html.EditorFor (x = & gt; x.Date)% & gt; & Lt; Input type = "submit" value = "ok" /> & Lt;%}% & gt; & Lt; / ASP: Content & gt;   

And after that you can have a separate javascript file in which you will attach the datepicker after adding jquery and jquery UI scripts to your page:

 < Code> $ (function () {$ ('# date'). DateTime ();});   

And if you want the form to be self-collected when the user raises a value:

  $ (function () {$ (' # Date ') .Datepicker ({on select: function (dateText, inst) {$ (' form '). Trigger (' submit ');}});});   

Here's a good place to start with the MVC:

Comments