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

How to Validate textbox in grid on button click also in the grid

1 Answer 413 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Brendan
Top achievements
Rank 1
Brendan asked on 21 Dec 2020, 10:02 PM

So i have a textbox field that needs a few alerts and a confirm when a value is entered and the button in the grid is clicked to save the value of the textbox to the database.  How would this be achieved?

<telerik:GridTemplateColumn HeaderText="New Price" UniqueName="newprice">
<ItemTemplate> <asp:TextBox ID="txtNewPrice" runat="server" ></asp:TextBox> </ItemTemplate
</telerik:GridTemplateColumn
 <telerik:GridTemplateColumn HeaderText="Action" UniqueName="Action"> <ItemTemplate> <asp:Button ID="btnOverride" Text="Override" runat="server" OnClientClick="return Validate();" OnClick="Override_Click"></asp:Button> </ItemTemplate>  </telerik:GridTemplateColumn>

1 Answer, 1 is accepted

Sort by
0
Eyup
Telerik team
answered on 24 Dec 2020, 01:13 PM

Hello Brendan,

 

Generally, RadGrid provides build-in validation capabilities:
https://docs.telerik.com/devtools/aspnet-ajax/controls/grid/data-editing/validation

For this specific requirement, you can use the following approach:
Pass the button to the function:

OnClientClick="return Validate(this);"
function Validate(buttonEl){
  var button = $(buttonEl);
  var row = button.parents("tr").first();
  
  var textBox = row.find("#txtNewPrice");
  return textBox().val() == "";
}
Or .text();

I hope this will prove helpful.

 

Regards,
Eyup
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Tags
Grid
Asked by
Brendan
Top achievements
Rank 1
Answers by
Eyup
Telerik team
Share this question
or