3
votes

I have a "RadGrid" for Editing Data.

I have filtering enabled.

I perform validations using the "RadInputManager".

When I try to update changes 'RadInputManager' is validating the 'TextBox' filters too.

How I can solve this?

I add the code "aspx" to show the example:

<telerik:RadAjaxManager runat="server">
    <AjaxSettings>
        <telerik:AjaxSetting AjaxControlID="RadGrid1">
            <UpdatedControls>
                <telerik:AjaxUpdatedControl ControlID="RadGrid1" UpdatePanelCssClass="" />
                <telerik:AjaxUpdatedControl ControlID="RadInputManager1" UpdatePanelCssClass="" />
            </UpdatedControls>
        </telerik:AjaxSetting>
    </AjaxSettings>
</telerik:RadAjaxManager>
<telerik:RadScriptManager ID="RadScriptManager1" runat="server">
    <Scripts>
        <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.Core.js">
        </asp:ScriptReference>
        <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.jQuery.js">
        </asp:ScriptReference>
        <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.jQueryInclude.js">
        </asp:ScriptReference>
    </Scripts>
</telerik:RadScriptManager>
        <telerik:RadInputManager ID="RadInputManager1" runat="server">
    <telerik:TextBoxSetting InitializeOnClient="False" ErrorMessage="Required!" Validation-IsRequired="True" Validation-ValidateOnEvent="Submit">
        <TargetControls>
            <telerik:TargetInput ControlID="RadGrid1" />
        </TargetControls>
    </telerik:TextBoxSetting>
</telerik:RadInputManager>

<telerik:RadGrid ID="RadGrid1" runat="server" AllowAutomaticDeletes="True" AllowAutomaticInserts="True" AllowAutomaticUpdates="True" AllowFilteringByColumn="True" AllowPaging="True" AllowSorting="True" AutoGenerateColumns="False" AutoGenerateEditColumn="True" CellSpacing="0" DataSourceID="LinqDataSource1" EnableHeaderContextFilterMenu="True" EnableHeaderContextMenu="True" GridLines="None">
    <MasterTableView CommandItemDisplay="Top" DataKeyNames="RolId" DataSourceID="LinqDataSource1" EditMode="InPlace">
        <Columns>
            <telerik:GridBoundColumn DataField="Name" HeaderText="Name" SortExpression="Name" UniqueName="Name">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="Description" HeaderText="Description" SortExpression="Description" UniqueName="Description">
            </telerik:GridBoundColumn>
        </Columns>
    </MasterTableView>
</telerik:RadGrid>
<asp:LinqDataSource ID="LinqDataSource1" runat="server" ContextTypeName="WebApplication1.DataClasses1DataContext" EntityTypeName="" TableName="Rol">
</asp:LinqDataSource>

Thank,

Delvis

1
please explain what you mean by 'update changes'. - Brett Caswell
... admittedly, I haven't worked too much with this form of validation. However, it is apparent to me that you are not supposed to designated the entire Grid as the target input control. However, I'm not sure how you would use the RadInputManager on auto generated edit state bound controls. - Brett Caswell
yeah.. I can see from reviewing RadInputManager, and the demo, that they are promoting targeting the RadGrid, but then do not use filters on the grid.. nor do they account for this scenerio in their sample demo.. demos.telerik.com/aspnet-ajax/input/examples/radinputmanager/… .. it shouldn't be that difficult to determine in either client or server code, which control is raising the validation event. - Brett Caswell
Do not have enough points to put a picture showing the problem. 'update changes' means you want to save the change ("Submit"). I want to use Telerik controls without using much additional code. Wish the validator consider only those controls that have the same ValidationGroup. - Delvis

1 Answers

1
votes

It appears that you can add the Validation Behavior to your bound controls dynamically using the RadGrid ItemCreated Event, and declaring the Telerik:TextBoxSetting without designating a Target Control.

Front-End (Markup)

  <telerik:RadInputManager ID="RadInputManager1" runat="server">
      <telerik:TextBoxSetting BehaviorID="TextBoxBehavior1"  InitializeOnClient="False" ErrorMessage="Required!" Validation-IsRequired="True" Validation-ValidateOnEvent="Submit">        
      </telerik:TextBoxSetting>
  </telerik:RadInputManager>

  <telerik:RadGrid ID="RadGrid1" runat="server" OnItemCreated="RadGrid1_ItemCreated" AllowAutomaticDeletes="True" AllowAutomaticInserts="True" AllowAutomaticUpdates="True" AllowFilteringByColumn="True" AllowPaging="True" AllowSorting="True" AutoGenerateColumns="False" AutoGenerateEditColumn="True" CellSpacing="0" DataSourceID="LinqDataSource1" EnableHeaderContextFilterMenu="True" EnableHeaderContextMenu="True" GridLines="None">
      <MasterTableView CommandItemDisplay="Top" DataKeyNames="RolId" DataSourceID="LinqDataSource1" EditMode="InPlace">
          <Columns>
              <telerik:GridBoundColumn DataField="Name" HeaderText="Name" SortExpression="Name" UniqueName="Name">
              </telerik:GridBoundColumn>
              <telerik:GridBoundColumn DataField="Description" HeaderText="Description" SortExpression="Description" UniqueName="Description">
              </telerik:GridBoundColumn>
          </Columns>
      </MasterTableView>
  </telerik:RadGrid>

Code-Behind

 protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e)
{
    if (e.Item is GridEditableItem && e.Item.IsInEditMode)
    {
        GridEditFormItem editedItem = e.Item as GridEditFormItem;

        TextBoxSetting inputSettings = (DateInputSetting)RadInputManager1.GetSettingByBehaviorID("TextBoxBehavior1");

        RadTextBox tbName = editedItem.FindControl("tbName") as RadTextBox;
        RadTextBox tbDescription = editedItem.FindControl("tbDescription") as RadTextBox; 

        inputSettings.TargetControls.Add(new TargetInput(tbName.UniqueID, true));
        inputSettings.TargetControls.Add(new TargetInput(tbDescription.UniqueID, true));            
    }
}

note that tbName and tbDescription, in likelyhood, don't exist. Certainly there is a textbox being created for both each of those datafields, but you'll have to discover what the control's generated names are if you leave the columns as telerik:GridBoundColumns... The alternative is to use a GridTemplateColumn.

Alternative Column (Mark-up : RadGrid > MasterTableView > Column)

 <telerik:GridTemplateColumn HeaderText="Name" SortExpression="Name">
     <ItemTemplate>
         <%# DataBinder.Eval(Container.DataItem, "Name") %>
     </ItemTemplate>
     <EditItemTemplate>
         <telerik:RadTextBox ID="tbName" Width="60px" runat="server" Text='<%# Bind("Name")%>'>
         </telerik:RadTextBox>
     </EditItemTemplate>
 </telerik:GridTemplateColumn>
 <telerik:GridTemplateColumn HeaderText="Description" SortExpression="Description">
     <ItemTemplate>
         <%# DataBinder.Eval(Container.DataItem, "Description") %>
     </ItemTemplate>
     <EditItemTemplate>
         <telerik:RadTextBox Width="245px" ID="tbDescription" runat="server" TextMode="MultiLine" Resize="Both" Text='<%# Bind("Description")%>' EmptyMessage="type description"> 
         </telerik:RadTextBox>
     </EditItemTemplate>
 </telerik:GridTemplateColumn>

This should work for you, let me know.. I haven't put it to the test.