Validate TextBox in each row of RadGrid using RadInputManager

4 posts, 0 answers
  1. Drew
    Drew avatar
    2 posts
    Member since:
    Aug 2011

    Posted 02 Aug 2011 Link to this post

    Hi!

    I'm trying to speed up performance in a User Control Edit Form used to edit items from a main grid.  Currently, the custom edit form opens in 3-5 seconds.  I've isolated the problem to a grid on the edit form which contains four RadNumericTextBox editors in each row.  If I remove these, the form opens and closes in less than a second.

    I followed guidance on these forums to replace the RadNumericTextBoxes with asp:TextBox and use a RadInputManager to validate the input.  In the grid's ItemCreated event, I assign each TextBox to the RadInputManager's control collection.  The problem is, the controls in the grid rows don't seem to pick up any of the validation.  I even added a test TextBox on the form to verify that the input manager was configured correctly.

    The grid columns are defined like this (I changed two of the four to TextBox for testing):

    <telerik:GridTemplateColumn HeaderStyle-Width="100" HeaderText="Min Distance" UniqueName="MinDistance">
         <ItemTemplate>
             <telerik:RadNumericTextBox ID="rntbMinDistance" Type="Number" MinValue="0" MaxLength="4"
                 NumberFormat-DecimalDigits="0" NumberFormat-GroupSeparator="" Width="40" DbValue='<%# Eval("MinDistanceToLocation") %>'
                 Enabled='<%# Eval("IsIncludedInOrder") %>' runat="server" />
         </ItemTemplate>
     </telerik:GridTemplateColumn>
     <telerik:GridTemplateColumn HeaderStyle-Width="100" HeaderText="Max Distance" UniqueName="MaxDistance">
         <ItemTemplate>
             <telerik:RadNumericTextBox ID="rntbMaxDistance" Type="Number" MinValue="0" MaxLength="4"
                 NumberFormat-DecimalDigits="0" NumberFormat-GroupSeparator="" Width="40" DbValue='<%# Eval("MaxDistanceToLocation") %>'
                 Enabled='<%# Eval("IsIncludedInOrder") %>' runat="server" />
         </ItemTemplate>
     </telerik:GridTemplateColumn>
     <telerik:GridTemplateColumn HeaderStyle-Width="100" HeaderText="Min HSGY" UniqueName="MinHSGY">
         <ItemTemplate>
             <asp:TextBox ID="txtMinHSGY" Type="Number" Width="40" Text='<%# Eval("MinHighSchoolGraduationYear") %>'
                  runat="server" />
         </ItemTemplate>
     </telerik:GridTemplateColumn>
     <telerik:GridTemplateColumn HeaderStyle-Width="100" HeaderText="Max HSGY" UniqueName="MaxHSGY">
         <ItemTemplate>
             <asp:TextBox ID="txtMaxHSGY" Type="Number" Width="40" Text='<%# Eval("MaxHighSchoolGraduationYear") %>'
                  runat="server" />
         </ItemTemplate>
     </telerik:GridTemplateColumn>


    I defined the input manager as follows: 

    <telerik:RadInputManager ID="RadInputManager1" runat="server" >
        <telerik:NumericTextBoxSetting BehaviorID="hsgyBehavior" InitializeOnClient="false"
            ErrorMessage="Valid year is required" Type="Number" DecimalDigits="0" MinValue="1900"
            MaxValue="2099" >
            <TargetControls>
                <telerik:TargetInput ControlID="txtTest" />
            </TargetControls>
        </telerik:NumericTextBoxSetting>
    </telerik:RadInputManager>


    And finally, I added this handler to the grid: 

    protected void rgrdLocations_ItemCreated(object sender, GridItemEventArgs e)
    {
        if (e.Item is GridDataItem && e.Item.IsDataBound && e.Item.DataItem != null)
        {
            NumericTextBoxSetting hsgySetting = (NumericTextBoxSetting)RadInputManager1.GetSettingByBehaviorID("hsgyBehavior");
             
            TextBox txtMinHSGY = e.Item.FindControl("txtMinHSGY") as TextBox;
            TextBox txtMaxHSGY = e.Item.FindControl("txtMaxHSGY") as TextBox;
            hsgySetting.TargetControls.Add(new TargetInput(txtMinHSGY.UniqueID, true));
            hsgySetting.TargetControls.Add(new TargetInput(txtMaxHSGY.UniqueID, true));
        }
    }

    txtTest validates as expected, but the textBoxes in the grid do not.  What am I missing?

    I'm new to Telerik and new to web development, so I apologize if it's something obvious.

    Thanks,

    Drew
  2. Tsvetina
    Admin
    Tsvetina avatar
    2481 posts

    Posted 05 Aug 2011 Link to this post

    Hello Drew,

    Have you tried debugging your code to confirm that it steps through the code that adds the target controls? I would advise you to check whether leaving only if(e.Item is GridDataItem) as a check changes the textboxes behavior.

    Best wishes,
    Tsvetina
    the Telerik team

    Browse the vast support resources we have to jump start 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.

  3. Drew
    Drew avatar
    2 posts
    Member since:
    Aug 2011

    Posted 05 Aug 2011 Link to this post

    Hi Tsvetina,

    I have tried, and the code is executed.  The popup form's grid was bound to a SQLDataSource declaratively, and the 1 parameter's value was set in code during the EditCommand from the parent grid.  Through process of elimination, I found that skipping that line of code fixes the problem (but obviously doesn't retrieve the correct data).  To fix, I removed the declarative binding and instead use the OnNeedDatasource event to set the grid's DataSource property.  Now, everything else works as expected.  Any idea why that would happen?  Was I doing something incorrectly?

    Also, I did some comparisons and while using asp:TextBox instead of RadNumericTextBox is quicker, I could boost performance even more if I could add the controls to the RadInputManager on the client-side as they are selected.  Any hint on how that could be done?

    Thanks again,

    Drew
  4. Tsvetina
    Admin
    Tsvetina avatar
    2481 posts

    Posted 11 Aug 2011 Link to this post

    Hello Drew,

    I am not sure why exactly the part with the datasource prevented the rest of the code from working, it should not be directly related. If you want to go back to declarative binding, you can paste the problemmatic code and we will check it for possible problems.

    As for your second question, since the input manager settings require server-side processing, they can be set only in code behind but this should not be a problem for performance.

    All the best,
    Tsvetina
    the Telerik team

    Browse the vast support resources we have to jump start 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.

Back to Top