WebGrid provides an OnRowValidate client side events.

In this topic, you will learn the basic thing on how to validate empty cell when adding new row using OnRowValidate.

To validate empty cell when adding new row using OnRowValidate

  1. Select WebGrid's instance and press F4.
  2. In Layout Settings, select ClientSideEvents, then set OnRowValidate to WebGrid1_OnRowValidate.
  3. Write the following function in OnRowValidate client side event:

    function WebGrid1_OnRowValidate(rowObject)
      var cellName = wgGetCellByName(rowObject, "ContactName");
      if (cellName.cellValue == "" || typeof(cellName.cellValue) == "undefined") 
        alert("You must fill in ContactName.");
            // set focus the cellProduct and activate edit mode.
            // return false so that the addnew will not process.
            return false;
      return true;
  4. Run the project.

Related Topics