日期编辑 在客户端设置日期值
本文关键字:日期 设置 编辑 客户端 | 更新日期: 2023-09-27 18:32:44
如何设置日期从一个日期编辑到另一个日期。我有两个日期编辑属性。当一个日期编辑(date1)更改时,我需要在另一个日期编辑上设置一些值。我已经创建了具有一些逻辑的ondatechange函数,然后我需要将值设置为date2字段。我已经使用 JS/jQuery 进行了设置,但在聚焦或单击更改的 date2 日期编辑后,该值无法正确绑定。
在我看来
@Html.Hidden("dateTemp")
<label>R2Date</label>
@Html.DevExpress().DateEdit(
settings =>
{
settings.Name = "date1";
settings.Properties.NullText = "MM/dd/yyyy";
settings.Properties.EditFormat = EditFormat.Custom;
settings.Properties.EditFormatString = "MM/dd/yyyy";
settings.Width = System.Web.UI.WebControls.Unit.Percentage(27);
settings.Properties.ClientSideEvents.DateChanged = "OnDateChanged";
}).Bind(Model.r2date).GetHtml()
<label>RDate</label>
@Html.DevExpress().DateEdit(
settings =>
{
settings.Name = "date2";
settings.Properties.NullText = "MM/dd/yyyy";
settings.Properties.EditFormat = EditFormat.Custom;
settings.Properties.EditFormatString = "MM/dd/yyyy";
settings.Width = System.Web.UI.WebControls.Unit.Percentage(27);
settings.Properties.ClientSideEvents.DateChanged = "ReportOnDateChanged";
}).Bind(Model.date1).GetHtml()
[JScript]
function OnDateChanged(s, e) {
var dateVal = s.GetText();
//my logic here
dateOnchange();
}
dateOnchange(){
//my logic here just need to call reportondatechange()
ReportOnDateChanged();
}
function ReportOnDateChanged(s,e )
{
dateVal1 = $("#dateTemp").val(); //dateval1 has some values here
s.SetDate(dateVal1);//not working how to set the value here
}
https://documentation.devexpress.com/#AspNet/DevExpressWebScriptsASPxClientControl_GetControlCollectiontopic
这应该做到
var editor = ASPxClientControl.GetControlCollection().GetByName("date2");
if (editor) {
editor.SetValue(dateVal1);
}
$("#date2").val(dateVal1);