I want to create a CustomValidator that will ensure that one of two different controls has a value. How do I get a reference to both controls in the ServerValidate event? My grid looks something like:
Notice that my CustomValidator does not have a ControlToValidate value because I want to ensure that either the ContactEdit combo box has a value or the description has a value. Is there a way to do this or am I required to have a custom edit form?
| <telerik:RadGrid ID="MyGrid" runat="server" |
| OnNeedDataSource="MyGrid_NeedDataSource" |
| OnItemDataBound="MyGrid_ItemDataBound" |
| OnInsertCommand="MyGrid_InsertCommand" |
| OnUpdateCommand="MyGrid_UpdateCommand" |
| OnDeleteCommand="MyGrid_DeleteCommand" |
| > |
| <MasterTableView DataKeyNames="Key" CommandItemDisplay="Top" EditMode="InPlace"> |
| <Columns> |
| <telerik:GridEditCommandColumn ButtonType="ImageButton" UniqueName="EditCommandColumn" |
| <HeaderStyle Width="40px" HorizontalAlign="Center" /> |
| <ItemStyle Width="40px" HorizontalAlign="Center" /> |
| </telerik:GridEditCommandColumn> |
| <telerik:GridTemplateColumn UniqueName="Category" HeaderText="Category"> |
| <ItemStyle Width="100px" /> |
| <HeaderStyle Width="100px" /> |
| <ItemTemplate> |
| <%#DataBinder.Eval(Container.DataItem, "Category.Name") %> |
| </ItemTemplate> |
| <EditItemTemplate> |
| <telerik:RadComboBox ID="CategoryEdit" runat="server" |
| Width="100%" |
| DataSourceID="CategoryDataSource" |
| DataTextField="Name" DataValueField="Key" |
| SelectedValue='<%#Bind("CategoryKey") %>'> |
| </telerik:RadComboBox> |
| </EditItemTemplate> |
| </telerik:GridTemplateColumn> |
| <telerik:GridTemplateColumn UniqueName="Contact" HeaderText="Contact"> |
| <ItemStyle Width="150px" /> |
| <HeaderStyle Width="150px" /> |
| <ItemTemplate> |
| <%#DataBinder.Eval( Container.DataItem, "ContactName" )%> |
| </ItemTemplate> |
| <EditItemTemplate> |
| <telerik:RadComboBox ID="ContactEdit" runat="server" |
| Width="100%" |
| DataSourceID="ContactDataSource" |
| DataTextField="Name" DataValueField="Key" |
| SelectedValue='<%#Bind("ContactKey") %>'> |
| <asp:CustomValidator ID="ContactOrDescriptionValidator" runat="server" |
| Display="Dynamic" |
| ErrorMessage="Item must have a contact or a description." |
| OnServerValidate="MyGrid_ContactOrDescriptionValidator_ServerValidate" |
| > |
| </asp:CustomValidator> |
| </EditItemTemplate> |
| </telerik:GridTemplateColumn> |
| <telerik:GridTemplateColumn UniqueName="Description" HeaderText="Description"> |
| <ItemStyle Width="150px" /> |
| <HeaderStyle Width="150px" /> |
| <ItemTemplate> |
| <%#DataBinder.Eval( Container.DataItem, "Description" )%> |
| </ItemTemplate> |
| <EditItemTemplate> |
| <telerik:RadTextBox ID="DescriptionEdit" runat="server" |
| Width="100%" MaxLength="50" |
| Text='<%#Bind("Description") %>'> |
| </telerik:RadTextBox> |
| </EditItemTemplate> |
| </telerik:GridTemplateColumn> |
| <telerik:GridButtonColumn ButtonType="ImageButton" UniqueName="DeleteColumn" |
| CommandName="Delete" |
| <HeaderStyle Width="20px" HorizontalAlign="Center" /> |
| <ItemStyle Width="20px" HorizontalAlign="Center" /> |
| </telerik:GridButtonColumn> |
| </Columns> |
| </MasterTableView> |
| </telerik:RadGrid> |
Notice that my CustomValidator does not have a ControlToValidate value because I want to ensure that either the ContactEdit combo box has a value or the description has a value. Is there a way to do this or am I required to have a custom edit form?