Hello,
We are using RadGrid with batch Edit functionality. We have created javascript functions for textbox validation like allowing only numbers, only letters, only numbers and letters,.., the javascript functions are working fine.
The problem is to check textbox empty or not. We applied Requiredfieldvalidator for EditItemTemplate, it is not working fine.
We tried with Javascript but not getting how to set focus in textbox, if the textbox is empty.
ASPX:
-------
<telerik:GridTemplateColumn DataField="Product_Name" GroupByExpression="Product_Name Group by Product_Name"
UniqueName="Product_Name" InitializeTemplatesFirst="false" HeaderStyle-Width="20%"
HeaderText="Product Name" HeaderStyle-Font-Size="13px">
<HeaderTemplate>
<table>
<tr>
<td>
<asp:LinkButton ID="lnkSortProduct_Name" runat="server" CommandArgument="Product_Name"
CommandName="Sort" Text="Product Name"></asp:LinkButton>
</td>
<td>
<img src="Images/Context_new_menu.jpg" style="margin-top: 5px; margin-left: 5px;
cursor: pointer" onclick='ShowColumnHeaderMenu(event,"Product_Name")' alt="Show context menu" />
</td>
</tr>
</table>
</HeaderTemplate>
<ItemTemplate>
<asp:Label ID="lblProductName" runat="server" Text='<%#Eval("Product_Name") %>'></asp:Label>
</ItemTemplate>
<ItemStyle HorizontalAlign="Left" />
<EditItemTemplate>
<asp:TextBox ID="txtProductName" runat="server" Text='<%Eval("Product_Name") %>' Width="95px"
MaxLength="10" onblur="return Validate();" OnTextChanged="txtTaxYear_TextChanged" ToolTip="Enter Product Name"></asp:TextBox>
<span id="spntxtProductName" style="color:Red; visibility:hidden">*Required</span>
</telerik:GridTemplateColumn>
Javascript:-
--------------
function Validate()
{
var grid = $find("<%=grdTaxYears.ClientID %>");
var MasterTable = grid.get_masterTableView();
var row = MasterTable.get_dataItems();
var columns = grid.get_masterTableView().get_columns();
var ProductName = MasterTable.get_dataItems()[0].findElement('txtProductName');
var spntxtTaxYear = document.getElementById('spntxtTaxYear');
if ((ProductName .value == '') || (ProductName .value == null))
{
spntxtProductName.style.display = true;
return false;
}
}
Please resolve this issue.
Thanks in Advance,
Sanath Rohilla.
We are using RadGrid with batch Edit functionality. We have created javascript functions for textbox validation like allowing only numbers, only letters, only numbers and letters,.., the javascript functions are working fine.
The problem is to check textbox empty or not. We applied Requiredfieldvalidator for EditItemTemplate, it is not working fine.
We tried with Javascript but not getting how to set focus in textbox, if the textbox is empty.
ASPX:
-------
<telerik:GridTemplateColumn DataField="Product_Name" GroupByExpression="Product_Name Group by Product_Name"
UniqueName="Product_Name" InitializeTemplatesFirst="false" HeaderStyle-Width="20%"
HeaderText="Product Name" HeaderStyle-Font-Size="13px">
<HeaderTemplate>
<table>
<tr>
<td>
<asp:LinkButton ID="lnkSortProduct_Name" runat="server" CommandArgument="Product_Name"
CommandName="Sort" Text="Product Name"></asp:LinkButton>
</td>
<td>
<img src="Images/Context_new_menu.jpg" style="margin-top: 5px; margin-left: 5px;
cursor: pointer" onclick='ShowColumnHeaderMenu(event,"Product_Name")' alt="Show context menu" />
</td>
</tr>
</table>
</HeaderTemplate>
<ItemTemplate>
<asp:Label ID="lblProductName" runat="server" Text='<%#Eval("Product_Name") %>'></asp:Label>
</ItemTemplate>
<ItemStyle HorizontalAlign="Left" />
<EditItemTemplate>
<asp:TextBox ID="txtProductName" runat="server" Text='<%Eval("Product_Name") %>' Width="95px"
MaxLength="10" onblur="return Validate();" OnTextChanged="txtTaxYear_TextChanged" ToolTip="Enter Product Name"></asp:TextBox>
<span id="spntxtProductName" style="color:Red; visibility:hidden">*Required</span>
</telerik:GridTemplateColumn>
Javascript:-
--------------
function Validate()
{
var grid = $find("<%=grdTaxYears.ClientID %>");
var MasterTable = grid.get_masterTableView();
var row = MasterTable.get_dataItems();
var columns = grid.get_masterTableView().get_columns();
var ProductName = MasterTable.get_dataItems()[0].findElement('txtProductName');
var spntxtTaxYear = document.getElementById('spntxtTaxYear');
if ((ProductName .value == '') || (ProductName .value == null))
{
spntxtProductName.style.display = true;
return false;
}
}
Please resolve this issue.
Thanks in Advance,
Sanath Rohilla.