Urgent : Validate datetime of format dd/mmm/yyyy format

Posted by: infosyssitesupport on 8 September 2017, 7:59 pm EST

  • Posted 8 September 2017, 7:59 pm EST

    Hi,

      We are using farpoint spread version v4.0.3507 in our asp.net application.We have used the AJAX control tool kit's DateCalendarCellType in our application.On double click of the cell, the calendar control appears over the cell and the user can select the date from it,

    I have follwoing clarifications needed :

    1. In case if the user tried to edit the date value with an invalid dateformat other than "dd/mmm/yyyy" format or with an invalid text, on click of save , the spread would highlight those cells with invalid datetime format specified. Currently, the spread is placed with in the update panel. On click of the save button, We call a java script function to display "Save in Progress" message followed by data saved successfully. Is there any way such that I can validate the spread if all the cell values are in the correct format?

    On click of save button:

    void btnSave_Click(object sender, ImageClickEventArgs e)

    {

    FpSpreadTestPlan.SaveChanges();

    //// can we validate the spread here??? Is there any way we can validate the datetime cell before the "Save in progress" message is shown?

    SaveChanges();// this saved the data into the database

    }

    2. In case if we use the .htc files for custom datetime cell type, please can you guide me as how to validate the value for dd/mmm/yyyy date format?

    Any guidance at the earliest will be of much help.

    Thanks. 

     

     

    2010/03/calendarControl.GIF
  • Posted 8 September 2017, 7:59 pm EST

    Hello,



    1) When you call SaveChanges method, the UpdateCommand event will fire. During this event, you can iterate through all the edited columns. Then you can compare the value of changed column with the value in the desired format.



    2) For validating using the HTC file, I would suggest you to take a look on this forum post in which similar issue had been discussed.



    Regards,

    Ankit Nigam



  • Posted 8 September 2017, 7:59 pm EST

    Hi Ankit,

               The code for save changes is NOT inside the button command event of the spread. It is placed outside the spread's button command i.e the save button has its own onclick event specified.

    btnSave.Attributes.Add("onclick", "SaveChanges();");

    btnSave.Click += new ImageClickEventHandler(btnSave_Click); // The "save" button is an image button

    JS function:

    function SaveChanges() {

    document.getElementById("hdnDataSaved").value = "N";

    document.getElementById("lblProgress").innerText = 'Save in progress...';

    document.getElementById("lblProgress").style.display = 'block';

    if (document.getElementById("lblMessage") != null) {

    document.getElementById("lblMessage").style.display = 'none';

    }

    }

    //Button click event called following this 

     

    void btnSave_Click(object sender, ImageClickEventArgs e)

    {

    FpSpreadTestPlan.SaveChanges();

    SaveChanges();

    }

    Moerover, only when the user has typed in correct values, the control gets inside the "FpSpreadTestPlan_UpdateCommand" command.Otherwise, it doesnt get inside the update command.

    Can you suggest me if any validation can be done from the client side such that I can prevent from showing the "Save In progress" message on client click of the save button follwed by the "btnSave_Click" event(inside which i save the spread to viewstate and then call the server side function "savechanges()" to save into the database ?

    Thanks.

     

  • Posted 8 September 2017, 7:59 pm EST

    Please can you let me know if there is any updates on thr above issue? Is there any was I can validate the spread when invalid datetime value is entered by the user in the DateCalendarCellType cell ? The concern here is, the invalid datevalues are not saved in the view state of the spread(fpspread.savechanges()). So, even when the server side save function is called, other valid values also get discarded from getting saved.

     

     

     

  • Posted 8 September 2017, 7:59 pm EST

    Hello,



    You can create your own java script function to validate the date in the correct format. You can call this function from the client side SaveChanges() function.



    In your custom java script function you can iterate through all the rows of your DataCalenderCellType column. Using client side GetValue() method you can get the value of a cell. If the value is an invalid value then you can use the SetValue method to replace this value with a blank or default value.



    Regards,

    Ankit Nigam



  • Posted 8 September 2017, 7:59 pm EST

    Thanks Ankit.

    I have few questions.Did you mean to say that we got to call the fpspread.savechanges() method on the client side??

    And if its like we got to validate on the client side,then we got to check for the format , the value(i.e to check of the number of days for each month is within the specified raange , minimum and maximum date value).All these things need to be handled at the client side?? Then I guess the cell can be of simple datetime cell type/ a text cell type instead of the AJAX control's DataCalendar cellType.Please correct me if I am wrong.

    Can you guide me with a code snippent please?

     

    Thanks.

  • Posted 8 September 2017, 7:59 pm EST

    Hi,

    Have waited for hours together to get a response for this issue.But in vain.It really hampers the work to proceed further .  :(:(

  • Posted 8 September 2017, 7:59 pm EST

    Hello,



    Yes, you need to validate the date at the client side by calculating the number of days, months and years (i.e check of the number of days for each month is within the specified range, minimum and maximum date value). You can write the java script code explicitly to match date with format dd/mm/yyyy. You will get a value of cell using the GetValue() method of type string.



    You may refer the javascript code provide in over here. This code is for mm/dd/yyyy format. You may edit it as per your requirement.



    Also you can make validation in your client side function “SaveChanges()” and call FpSpreadTestPlan.SaveChanges(); method in the btnSave_Click event.



    Regards,

    Ankit Nigam



Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels