简体   繁体   中英

Pass Calendar object to a server side method using JavaScript in ASP.Net C#

I have below JavaScript and i need to pass Calendar object to a method in partial class via function in JavaScript . I have a asp:Calendar in my web forms application. i need to pass an object of it.

<script type="text/javascript">
    function SelectDates() {
        PageMethods.selectAvlDates(/* what is here ? */);
    }
</script>

C# 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 static void selectAvlDates(Calendar cal)
{
    cal.SelectedDayStyle.BackColor = System.Drawing.Color.Red;
}

How can i do this ?

Perhaps, you could do something trick.

protected void Vehicle_Calendar_DayRender(object sender, DayRenderEventArgs e)
{
  string id = "xxx"; // Unique Id, Guid.New() for example
  e.Cell.Attributes["onmouseover"] = "SelectDates("+id+")"; 
  e.Cell.Attributes["id"] = "xxx";
}

<script type="text/javascript">
    function SelectDates(id) {
        $('td[id="'+id+'"]').css('backgroundcolor',"#FF0000"); // JQuery library should be referenced
        //PageMethods.selectAvlDates(/* what is here ? */);
    }
</script>

Hope that could help.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM