This is a migrated thread and some comments may be shown as answers.

Validating a new record client-side

1 Answer 66 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Jason
Top achievements
Rank 1
Jason asked on 03 Aug 2011, 04:56 PM
I'm currently trying to validate a record in an AJAX Datagrid, for both editing and creation. I can easily do this in the code-behind (say, in the ItemCommand function), but I'm looking for a way to do this in JavaScript (to avoid an unnecessary postback). For example, lets say I have a grid with three columns. And for each record update / creation, if the second column is empty, the third one needs to be populated. I shouldn't have to post-back just to validate that these fields are populated.

Is there a clientside event I can subscribe to so that, prior to the page is being posted-back, I can do my validation and approve/cancel?

Much thanks in advance.

-J

1 Answer, 1 is accepted

Sort by
0
Tsvetina
Telerik team
answered on 09 Aug 2011, 09:41 AM
Hi Jason,

You could do client-side validation by attaching the onblur event of the textbox inside the grid edit form. This can be done in ItemCreated server-event of RadGrid as shown below:
protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e)
 {
     if (e.Item is GridEditableItem && e.Item.IsInEditMode)
     {
         ((e.Item as GridEditableItem)["ColumnUniqueName"].Controls[0] as TextBox).Attributes.Add("onblur", "validate(this);");
     }
 }
in aspx:
<script type="text/javascript">
    function validate(sender) {
        alert(sender); //do validation here
    }
</script>

Regards,
Tsvetina
the Telerik team

Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

Tags
Grid
Asked by
Jason
Top achievements
Rank 1
Answers by
Tsvetina
Telerik team
Share this question
or