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
- Select WebGrid's instance and press F4.
- In Layout Settings, select ClientSideEvents, then set OnRowValidate to WebGrid1_OnRowValidate.
- Write the following function in OnRowValidate client side event:
JavaScript Copy Code 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. ISGetObject("WebGrid1").ActivateEditMode(); // return false so that the addnew will not process. return false; } return true; }
- Run the project.
References
OnRowValidate Property
Other Resources
Walkthrough Topics
How-to Topics