简体   繁体   中英

DateEdit set a date value on the client side

How to set date from one dateEdit to another. I have two dateedit properties. When one dateEdit (date1) changes i need to set some value on another dateedit. I have created ondatechanged function which has some logics and then i need to set the value to date2 field. i have used js/jquery to set but the value does not bind properly after focusing or clicking the changed date2 Dateedit.

In my View

 @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

This should do it

 var editor = ASPxClientControl.GetControlCollection().GetByName("date2");
            if (editor) {
                editor.SetValue(dateVal1);
            }
            $("#date2").val(dateVal1);

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