title: Call server side methods using JavaScript in ASP.Net C#
body: <p>I have a <code>asp:Calendar</code> in my web forms application. I want to call a method in partial class when user mouse over the Calendar. I can change back color of dates <code>onmouseover</code> by adding below line in <code>DayRender</code> event of calendar as below.</p>
  
  <pre><code>e.Cell.Attributes["onmouseover"] = "this.style.backgroundColor='pink';";
  </code></pre>
  
  <p>But how can i call method in partial class <code>onmouseover</code>  ?</p>
  
  <p>I have tried as below. but it does not work.</p>
  
  <p><strong>in my aspx page</strong></p>
  
  <pre><code>&lt;asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server"&gt;
      &lt;script type="text/javascript"&gt;
          function SelectDates() {
              PageMethods.selectAvlDates();
          }
      &lt;/script&gt;
  &lt;/asp:Content&gt;
  
  &lt;asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server"&gt;
  
  &lt;asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="true"&gt;
  &lt;/asp:ScriptManager&gt;
  
  &lt;asp:Calendar ID="Vehicle_Calendar" runat="server" BackColor="#4b6c9e"
      Font-Names="Verdana" Font-Size="9pt" ForeColor="Black" Height="250px" NextPrevFormat="ShortMonth"
      OnPreRender="Vehicle_Calendar_PreRender" Width="330px" OnSelectionChanged="Vehicle_Calendar_SelectionChanged"
      CellSpacing="1" DayHeaderStyle-BackColor="#ffffff" OnDayRender="Vehicle_Calendar_DayRender"&gt;
      &lt;DayHeaderStyle Font-Bold="True" Font-Size="8pt" ForeColor="#333333" Height="8pt" /&gt;
      &lt;DayStyle BackColor="#CCCCCC" /&gt;
      &lt;NextPrevStyle Font-Bold="True" Font-Size="8pt" ForeColor="White" /&gt;
      &lt;OtherMonthDayStyle ForeColor="#999999" /&gt;
      &lt;TitleStyle BackColor="#4b6c9e" Font-Bold="True" Font-Size="12pt" ForeColor="White"
          Height="12pt" /&gt;
      &lt;SelectedDayStyle BackColor="#4b6c9e" ForeColor="White" /&gt;
      &lt;TodayDayStyle BackColor="#999999" ForeColor="White" /&gt;
  &lt;/asp:Calendar&gt;
  
  &lt;asp:Label ID="lblResult" runat="server"&gt;&lt;/asp:Label&gt;
  
  &lt;/asp:Content&gt;
  </code></pre>
  
  <p><strong>Code behind</strong></p>
  
  <pre><code>protected void Vehicle_Calendar_DayRender(object sender, DayRenderEventArgs e)
  {
    e.Cell.Attributes["onmouseover"] = "SelectDates()"; // called java script function from here
  }
  
  [System.Web.Services.WebMethod]
  public void selectAvlDates()
  {
      lblResult.Text = "mouse over";
  }
  </code></pre>
  
  <p>But label doesn't print <strong>mouse over</strong> when i move over the calendar.</p>
  
  <p>How can i do this ?</p>