Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4067220
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T16:13:19+00:00 2026-05-20T16:13:19+00:00

Can some please tell me why the event handler named MyCalendar_SelectionChanged is not getting

  • 0

Can some please tell me why the event handler named “MyCalendar_SelectionChanged” is not getting executed when I click on a day within calendar control? This is the simple aspx code from a sample ASP.NET MVC2 application:

<%@ Page Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage" %>

<script runat="server">
private void MyCalendar_SelectionChanged (object sender, System.EventArgs e) 
{
    //lbl1.Text = Calendar1.SelectedDate.ToString();
    Console.WriteLine("test");
} 
</script>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
    Home Page
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
  <form id="Form1" runat="server">
<h2><%= Html.Encode(ViewData["Message"]) %></h2>
    <p>
        To learn more about ASP.NET MVC visit <a href="http://asp.net/mvc" title="ASP.NET MVC Website">http://asp.net/mvc</a>.
    </p>

    <div>
    <asp:Calendar ID="Calendar1" runat="server" OnSelectionChanged="MyCalendar_SelectionChanged" />     

    </div>    
</form>    
</asp:Content>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T16:13:20+00:00Added an answer on May 20, 2026 at 4:13 pm

    <asp:Calendar runat="server" ... /> is a server control that relies on ViewState and PostBack which are notions that no longer exist in ASP.NET MVC so you shouldn’t be using any server controls. Because there are no postbacks and view callbacks your function won’t be triggered. Also make sure you remove the runat="server" tag from your form and use HTML helpers to generate forms.

    To implement a calendar in ASP.NET MVC you may checkout the jQuery UI datepicker.

    So here’s how you might proceed:

    As always you start with the M(odel) in MVC which will represent the information you are willing to show (in your case a date):

    public class MyViewModel
    {
        public DateTime Date { get; set; }
    }
    

    Then you get to the C(ontroller) in MVC:

    public class HomeController: Controller
    {
        // used to render the view
        public ActionResult Index()
        {
            var model = new MyViewModel
            {
                Date = DateTime.Now
            };
            return View(model);
        }
    
        // will be called when the form is submitted
        [HttpPost]
        public ActionResult Index(MyViewModel model)
        {
            return View(model);
        }
    }
    

    Then the V(iew) in MVC:

    <%@ Page 
        Language="C#" 
        MasterPageFile="~/Views/Shared/Site.Master" 
        Inherits="System.Web.Mvc.ViewPage<AppName.Models.MyViewModel>" 
    %>
    
    <asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
        <% using (Html.BeginForm()) { %>
            <%= Html.EditorFor(x => x.Date) %>
            <input type="submit" value="OK" />
        <% } %>
    </asp:Content>
    

    and then you could have a separate javascript file in which you would attach the datepicker after having included jquery and jquery UI scripts to your page:

    $(function() {
        $('#Date').datepicker();
    });
    

    and if you wanted the form to automatically submit when the user picks a value:

    $(function() {
        $('#Date').datepicker({
            onSelect: function(dateText, inst) { 
                $('form').trigger('submit');
            }
        });
    });
    

    A good place to start with MVC is here: http://asp.net/mvc

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How to pass parameters to [WebMethod] in Asp.Net(C#) ? Can some one please explain
What is meant by object serialization? Can you please explain it with some examples?
can you please tell me how can i run a program from Adobe air
How i can add some values to color Box in the TFontDialog? Or please
Can someone please tell me how exactly to use getExtra() and putExtra() for intents?
Please tell me some solution for how to stop app at background when we
Can some one specify the windows API, one need to use in order to
Can some one post an example of using syslog outputter for log4r, I am
Can some one explain to me the difference between categories and inheritance in Objective
How to read data from Bar Code Scanner in .net windows application? Can some

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.