【发布时间】:2015-08-16 04:05:39
【问题描述】:
我有一个通用的日期选择器,这个日期选择器在近 10 个页面上很常见,因为默认日期选择器日期设置为当前日期,当我选择该链接时,我有一个带有链接的页面(10 页中的 1 页) ,它包含一些日期(未来或过去),所以我希望链接选择的日期显示在日期选择器控件上,目前我能够做到这一点,我面临的问题是,相同的更改日期反映到其他 9 页我不需要,我应该能够看到它们的默认日期,即当前日期。
代码:
特定页面的方法我将其设置为特定日期
protected void QuickListDateNavigate(object sender, CommandEventArgs e)
{
DateTime newDate = DateTime.Parse((string)e.CommandArgument);
this.Parent.SessionObj.ViewDate = newDate;
}
这是将上述选定日期设置为链接选定日期以及其他 9 个页面的位置。
日期选择器.ascx.cs
protected override void OnPreRender(EventArgs e)
{
if (this.m_showDateText)
{
if (datepicker.Value == "")
{
PickerDate = ViewDate;
}
else
{
// ViewDate = DateTime.Parse(datepicker.Value);
ViewDate = this.Parent.SessionObj.ViewDate;
PickerDate = ViewDate;
}
}
base.OnPreRender(e);
}
之前它是设置当前日期的注释行,添加了下一个链接“ViewDate = this.Parent.SessionObj.ViewDate;”正如我预期的那样改变了日期。
public DateTime ViewDate
{
get
{
return Parent.SessionObj.ViewDate;
}
set
{
Parent.SessionObj.ViewDate = value;
}
}
protected DateTime PickerDate
{
get
{
DateTime newDate = ViewDate;//Use current ViewDate if Value in textbox is not valid.
string pickerValue = this.Parent.SessionObj.ViewDate.ToString();
try
{
newDate = DateTime.Parse(pickerValue);
}
catch
{
//Date was not a valid format fill in with the ViewDate
SetPickerDateToViewDate();
}
return newDate;
}
set
{
this.datepicker.Value = value.ToString(this.m_dateFormatString);
}
}
protected void SetPickerDateToViewDate()
{
PickerDate = ViewDate;
}
因此,一旦将日期更改为我的要求,它就不会设置回其他页面的当前日期,有什么办法可以将更改的日期用于特定页面和其他页面的默认日期??
【问题讨论】:
标签: javascript jquery asp.net datepicker