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

Grid EditForm in Template Mode pure Client JS validation?

3 Answers 158 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Sanjay
Top achievements
Rank 1
Sanjay asked on 17 Nov 2010, 05:48 PM
Hello,

Do you have some sample code to Validate the Modified data in Grid EditForm in Template Mode using pure Client side JavaScript validation?
In Add form the JS works fine as the controls are visible and directly accessible using <% controlName.ClientID %> but would like to have the validation in Update mode?

Thanks,
Sanjay

3 Answers, 1 is accepted

Sort by
0
Tsvetina
Telerik team
answered on 23 Nov 2010, 09:30 AM
Hello Sanjay,

Could you please elaborate a little more on what is the difference between your edit form in insert and edit mode? Is there any difference in controls visibility? What is the reason for validation to work differently on both.

Additionally, you can take a look at this forum thread, where client-side validation is discussed (there is also a sample project at the bottom).

All the best,
Tsvetina
the Telerik team
Browse the vast support resources we have to jumpstart 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.
0
Sanjay
Top achievements
Rank 1
answered on 23 Nov 2010, 09:50 PM
Hi Tsvetina,

What I meant in the Insert (Add) mode is that my Insert mode is above (outside) the radgrid and is not part of the Radgrid and the controls are visible directly in the code behind page and can also easily be accessed by javascript
But my Edit mode is within the RadGrid configured in the EditFormSettings template. Here ofcourse the code behind cannot directly access the controls withing the edit form and I have to use the Grid1.ItemCommand and in that use e.Item.FindControl("controlName") to find the controls and then validate it.

So my question is can we validate using clientside JAVASCRIPT after the Update button is clicked (one of the button in the EditFormTemplate) INSTEAD OF THE CODEBEHIND using the vb.net language?
If so can you refer/give a sample application?

Thanks,
Sanjay
0
Tsvetina
Telerik team
answered on 26 Nov 2010, 11:06 AM
Hello Sanjay,

In this scenario you can attach the OnLoad client-side event of the controls in the FormTemplate and there get references to them, which you can then use in the client-side OnCommand event handler of RadGrid to validate their values in case of "Update" command, e.g.
<FormTemplate>
     <telerik:RadTextBox
      ID="RadTextBox1" runat="server"
      Text='<%# DataBinder.Eval( Container, "DataItem.Country" ) %>' ClientEvents-OnLoad="LoadTextBox">
   </asp:TextBox>
</FormTemplate>
<script type="text/javascript">
var textBox;
function LoadTextBox(sender,eventArgs){
   textBox=sender;
}
  
function onCommand(sender,eventArgs){
   if(eventArgs.get_commandName()=="Update")
   {
      if(textBox.get_value()=="")
      {
         eventArgs.set_cancel(true);
      }
   }
}
</script>


Regards,
Tsvetina
the Telerik team
Browse the vast support resources we have to jumpstart 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
Sanjay
Top achievements
Rank 1
Answers by
Tsvetina
Telerik team
Sanjay
Top achievements
Rank 1
Share this question
or