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

javascript error checking

3 Answers 72 Views
Grid
This is a migrated thread and some comments may be shown as answers.
chris
Top achievements
Rank 1
chris asked on 10 Feb 2009, 02:06 AM
I have searched around for a while but have not found any code in the demos or forum on how to make the update button in an edit form on radgrid onclick run some client side error checking (code for accessing the ids of the text boxes a plus) and then if it passes move on to the RadGrid1_UpdateCommand.

Thanks for your help

3 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 10 Feb 2009, 07:12 AM
Hello Chris,

I suppose you are using AutoGeneratedEditForm. If so, you can try out the following code to achieve your scenario:
cs:
 protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e) 
    { 
        if (e.Item is GridEditableItem && e.Item.IsInEditMode) 
        { 
            GridEditableItem editItem = (GridEditableItem)e.Item; 
            string txtBoxID = ((TextBox)editItem["ColumnUniqueName"].Controls[0]).ClientID; 
            LinkButton updateBtn = (LinkButton)editItem.FindControl("UpdateButton"); 
            updateBtn.Attributes.Add("onClick", "return ErrorCheck('" + txtBoxID + "');"); 
        } 
   } 

js:
 <script type="text/javascript"
    function ErrorCheck(ID)     
    { 
       var textbox =document.getElementById(ID);   
       // check for error and if passed 
              
       var masterTable = $find("<%= RadGrid1.ClientID %>").get_masterTableView(); 
       masterTable.fireCommand("Update",""); // triggers the update command      
    } 
 </script> 

Thanks
Princy.
0
Accepted
SamJ
Top achievements
Rank 1
answered on 10 Feb 2009, 07:15 AM
Hi chris,

You can handle the ItemDataBound event of the grid and there attach client event handler of the Update button. And the textbox client IDs you can try passing as parameters of this handler. Something like below:

protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e) 
    if (e.Item is GridEditableItem && e.Item.IsInEditMode) 
    { 
        GridEditableItem editedItem = e.Item as GridEditableItem; 
        LinkButton updateButton = editedItem.FindControl("UpdateButton"as LinkButton; 
        TextBox txt1 = editedItem["BoundColumn1UniqueName"].Controls[0] as TextBox; 
        TextBox txt2 = editedItem["BoundColumn2UniqueName"].Controls[0] as TextBox; 
        //etc. for each grid column 
        updateButton.Attributes["onclick"] = "if(!ClientErrorCheckFunction('" + txt1.ClientID + "', '" + txt2.ClientID + "')) return false;"
    } 



More about accessing grid cells and row might be found here.

Tell me if there is something unclear.

SamJ
0
chris
Top achievements
Rank 1
answered on 10 Feb 2009, 02:18 PM
Thanks for the info. Ill give it a go and see if i have any other questions.

Tags
Grid
Asked by
chris
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
SamJ
Top achievements
Rank 1
chris
Top achievements
Rank 1
Share this question
or