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

How to set focus for radgrid text box template column?

3 Answers 70 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Sanath
Top achievements
Rank 1
Sanath asked on 12 Sep 2013, 04:08 PM
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.

3 Answers, 1 is accepted

Sort by
0
Jayesh Goyani
Top achievements
Rank 2
answered on 13 Sep 2013, 04:48 AM
Hello,

<script type="text/javascript">
           function Validate(obj) {
               obj.focus();
           }       
       </script>

<asp:TextBox ID="txtProductName" runat="server" Text="AsdaSD" Width="95px" MaxLength="10"
       onblur="return Validate(this);" ToolTip="Enter Product Name"></asp:TextBox>


Thanks,
Jayesh Goyani
0
Sanath
Top achievements
Rank 1
answered on 13 Sep 2013, 04:22 PM
Hi Jayesh,

   Thanks for reply. Actually, i am able to set focus on textbox in which the way you suggested. But, my problem is i want to set focus at the time of validation if the textbox is empty.

Can you please give me reply, how can i set requiredfieldvalidator for edititemtemplate textbox control (or)  to restrict insertion of record if the textbox is empty?

Thanks,
Sanath Rohilla.
0
Jayesh Goyani
Top achievements
Rank 2
answered on 16 Sep 2013, 09:32 AM
Tags
Grid
Asked by
Sanath
Top achievements
Rank 1
Answers by
Jayesh Goyani
Top achievements
Rank 2
Sanath
Top achievements
Rank 1
Share this question
or