Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I have a asp:Calendar 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 onmouseover by adding below line in DayRender event of calendar as below.

e.Cell.Attributes["onmouseover"] = "this.style.backgroundColor='pink';";

But how can i call method in partial class onmouseover ?

I have tried as below. but it does not work.

in my aspx page

<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
    <script type="text/javascript">
        function SelectDates() {
            PageMethods.selectAvlDates();
        }
    </script>
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">

<asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="true">
</asp:ScriptManager>

<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">
    <DayHeaderStyle Font-Bold="True" Font-Size="8pt" ForeColor="#333333" Height="8pt" />
    <DayStyle BackColor="#CCCCCC" />
    <NextPrevStyle Font-Bold="True" Font-Size="8pt" ForeColor="White" />
    <OtherMonthDayStyle ForeColor="#999999" />
    <TitleStyle BackColor="#4b6c9e" Font-Bold="True" Font-Size="12pt" ForeColor="White"
        Height="12pt" />
    <SelectedDayStyle BackColor="#4b6c9e" ForeColor="White" />
    <TodayDayStyle BackColor="#999999" ForeColor="White" />
</asp:Calendar>

<asp:Label ID="lblResult" runat="server"></asp:Label>

</asp:Content>

Code behind

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";
}

But label doesn't print mouse over when i move over the calendar.

How can i do this ?

share|improve this question
wouldn't it be easier to just find the label with a jquery selector instead of going in code-behind, and then setting the text in the front-end ? – Bobby5193 Jun 27 at 10:47
@Bobby5193 I have added this label for testing. my actual need is onmouseover get dates and add them to a List<DateTime>. – Bishan Jun 27 at 10:51

Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.