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

[Solved] Client Side Validation Problem

2 Answers 213 Views
Grid
This is a migrated thread and some comments may be shown as answers.
John
Top achievements
Rank 1
John asked on 21 May 2008, 12:59 AM

I have a rad grid that i'm doing a custom inline edit on, and when I press the save button, i'm trying to do a client side validation of some of the fields.  But the OnClientClick event seems to be completely blocking the post back.  Any ideas?

protected void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)  
{  
 
            if (e.Item is GridEditFormItem && e.Item.IsInEditMode)  
            {  
                 Button bs = editFormItem.FindControl("btnSave") as Button;  
                bs.OnClientClick = "return validateChanges('" + m_Value+ "');";  
            }  
}  
 
 

and the javascript function right now I just have
function validateChanges(val)
{
     return true;
}

but it never posts.  Any ideas?

my asp button is this:

<asp:Button ID="btnSave" CssClass="buttonSmall" runat="server" Text="Save" CommandName="Update"/>

always works till i put in the OnClientClick property

2 Answers, 1 is accepted

Sort by
0
John
Top achievements
Rank 1
answered on 21 May 2008, 10:59 PM
Well I found a solution, so I think this is a bug on telerik, but maybe its by design.

When using the onclientclick to do custom javascript validation, it prevents the UpdateCommand from ever firing, so this is how I solved it.

button.OnClientClick="return validateChanges('" + value + "', '" + button.ClientID + "');

and then in the javascript I do this:

function validateChanges(val, buttonID)
{
     if (val == somecondition)
     {
          var id = buttonID.replace(/_/g,"$");
          _doPostBack(id,'');
     }
     {
           return false; //though doesn't matter since it never worked before
      }
}

If there is a better solution out there, please let me know, but this is the only way I could get it to work.
0
Andy F.
Top achievements
Rank 1
Iron
answered on 22 Jun 2008, 02:24 PM

Assume that the control will ADD more code to the client-side event.  In other words, change your OnClientClick to something that will permit a fall-thru in case everything is perfect:

bs.OnClientClick = "if (!validateChanges('" + m_Value+ "')) return false;";   

In the case where your validation returns TRUE, the control's additional event code gets a chance to operate.
Tags
Grid
Asked by
John
Top achievements
Rank 1
Answers by
John
Top achievements
Rank 1
Andy F.
Top achievements
Rank 1
Iron
Share this question
or