如何使用c#将jquery datepicker中的选定日期存储在变量中? [英] How to store selected date from jquery datepicker in a variable using c#?

查看:50
本文介绍了如何使用c#将jquery datepicker中的选定日期存储在变量中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在aspx页面上有一个jQuery日历,为

I have a jquery calender on my aspx page as

<div id="selectDate"></div>

以下是JS:

var array = ["23/08/2013", "24/08/2013", "25/08/2013"];
    $("#selectDate").datepicker({
        onSelect: function(dateText,inst){
        $('#selectDate').submit();},
        defaultDate: "+1w",
        changeMonth: true,
        dateFormat: "dd/mm/yy",
        minDate: 0,
        maxDate: '+1y +0m -1d',
        numberOfMonths: 2,
        beforeShowDay: function (date) {
            var string = jQuery.datepicker.formatDate('yy-mm-dd', date);
            return [array.indexOf(string) == -1];
        }
    });

现在,我需要将从日期选择器中选择的日期存储到.cs页上的变量中,我知道我必须使用onSelect函数,但是我不知道该怎么做,我们将不胜感激.

Now, i need to store the selected date from the datepicker into the variable on .cs page,I know i have to use onSelect function, but I don't know how to do it, any help will be appreciated.

我正在使用Asp.net和C#.

I am using Asp.net and C#.

推荐答案

您可以获取日期,使用js将其放入asp.net隐藏字段中,然后将其发布回去时,可以将其放入C#变量中,像这样的东西:

You can get the date, put it in a asp.net hidden field using js and then when you post it back you can put it in a C# variable, something like this:

将隐藏字段添加到您的标记中:

Add hidden field to your markup:

<asp:HiddenField Id="myDate" runat="server"></asp:HiddenField>

获取日期并将其设置为回发之前的hiddenfield:

Get the date and set it to the hiddenfield before postback:

var currentDate = $( "#selectDate" ).datepicker( "getDate" );
$('#<% myDate.ClientID %'>).val(currentDate);

发布时,您可以在后面的代码中使用它:

And when you post it you can use this in your code behind:

var selectedDate = DateTime.Parse(myDate.Value);

这篇关于如何使用c#将jquery datepicker中的选定日期存储在变量中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆