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

Validation message in EditForm

3 Answers 94 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Helen
Top achievements
Rank 1
Helen asked on 19 Nov 2013, 09:23 PM
Hi,

I have placed a table in an edit form that contains validation on several textboxes. I'm trying to make the validation message to be right in the cell that contains the textbox.  It seems like if I'm doing soemthing like the code below in my ItemCommand event, the message would be in the "outer" table cell.  How do I access the table cell that's in the table within the <FormTemplate>?
<EditFormSettings EditFormType="Template">
    <EditColumn FilterControlAltText="Filter EditCommandColumn1 column" UniqueName="EditCommandColumn1">
    </EditColumn>
    <FormTemplate>
        <table class="auto-style1" border="2" >
            <tr>
                <td style="width:8%">Building Name:</td>
                <td style="width:8%">
                    <asp:TextBox ID="bldgname" runat="server" MaxLength="40" >                                 
                    </asp:TextBox>
                </td>
                <td style="width:8%">Column3</td>
                <td style="width:100%">Column4</td>
            </tr>
            <tr>
                <td>Address:</td>
                <td>
                    <asp:TextBox ID="address1" runat="server" Text='<%# Bind("bldgstreet1") %>'></asp:TextBox><br />
                    <asp:TextBox ID="address2" runat="server" Text='<%# Bind("bldgstreet2") %>'></asp:TextBox><br />
                </td>
                <td> </td>
                <td> </td>
            </tr>
            <tr>
                <td>City:</td>
                <td>
                    <asp:TextBox ID="bldgcity" runat="server" Text='<%# Bind("bldgcity") %>'></asp:TextBox><br />
                </td>
                <td> </td>
                <td> </td>
            </tr>
            <tr>
                <td>State:</td>
                <td>
                    <asp:TextBox ID="bldgstate" runat="server" Text='<%# Bind("bldgstate") %>'></asp:TextBox><br />
                </td>
                <td> </td>
                <td> </td>
            </tr>
            <tr style="width:5%; height:50px">
                <td>Zip:</td>
                <td>
                    <asp:TextBox ID="bldgzip" runat="server" Text='<%# Bind("bldgzip") %>'></asp:TextBox><br />
                </td>
                 
                <td>
                    <div>
                        <table width="100%">
                          <tr>
                            <td style="width:30%">
                                <asp:ImageButton ID="CertifyAddressImageButton" runat="server" ImageUrl="~/images/certificate32.png" OnClick="CertifyAddressImageButton_Click"/>
                            </td>
                            <td style="width:70%">
                                <asp:CheckBox ID="CheckBoxOverride" runat="server" Text="Override?" TextAlign="Left" Font-Size="Large" />
                            </td>      
                          </tr>
                         </table>
                     </div>
                </td>
                <td>
                   <telerik:RadComboBox ID="WireCenterRadComboBox" Runat="server" Height="200px" Width="200px" DropDownWidth="750px"
                        HighlightTemplatedItems="True" MarkFirstMatch="True"
                        EnableLoadOnDemand="True" Filter="StartsWith" EmptyMessage="Enter WireCenter Name..." ToolTip="Enter WireCenter Name to Filter list"
                        OnItemsRequested="WireCenterRadComboBox_ItemsRequested" OnLoad="WireCenterRadComboBox_Load">
                        <HeaderTemplate>
                            <table style="width: 700px" cellspacing="0" cellpadding="0">
                                <tr>
                                    <td style="width: 80px;">WireCenter</td>
                                    <td style="width: 150px;">Name</td>
                                    <td style="width: 150px;">T1OrderMethod</td>
                                    <td style="width: 100px;">Vendor ACTL</td>
                                    <td style="width: 170px;">Logix ACTL</td>
                                </tr>
                            </table>
                        </HeaderTemplate>
                        <ItemTemplate>
                            <table style="width:700px" cellspacing="0" cellpadding="0">
                                <tr>
                                    <td style="width: 80px;"><%# DataBinder.Eval(Container, "Text")%></td>
                                    <td style="width: 150px;"><%# DataBinder.Eval(Container, "Attributes['wirecentername']")%></td>
                                    <td style="width: 150px;"><%# DataBinder.Eval(Container, "Attributes['t1ordermethod']")%></td>
                                    <td style="width: 100px;"><%# DataBinder.Eval(Container, "Attributes['vendoractl']")%></td>
                                    <td style="width: 170px;"><%# DataBinder.Eval(Container, "Attributes['logixactl']")%></td>
                                </tr>
                            </table>
                        </ItemTemplate>
                    </telerik:RadComboBox>
                </td>
                 
            </tr>
            <tr>
                <td>
                    <asp:Button ID="btnUpdate" Text='<%# (Container is GridEditFormInsertItem) ? "Insert" : "Update" %>'
                        runat="server" CommandName='<%# (Container is GridEditFormInsertItem) ? "PerformInsert" : "Update" %>'>
                    </asp:Button>
                    <asp:Button ID="btnCancel" Text="Cancel" runat="server" CausesValidation="False" CommandName="Cancel"></asp:Button>
                </td>
                <td> </td>
                <td> </td>
                <td> </td>
            </tr>
        </table>
    </FormTemplate>
</EditFormSettings>

if (e.CommandName == RadGrid.UpdateCommandName ||
    e.CommandName == RadGrid.PerformInsertCommandName)
{
    GridEditableItem item = e.Item as GridEditableItem;
    // Validate Zip Code
    RegularExpressionValidator validZip = new RegularExpressionValidator();
     
 
    // for Accessing boundcolumn
    GridTextBoxColumnEditor editor;
 
    // Test zip
    TextBox txtbx;
    TableCell cell;
 
    txtbx = (TextBox)item.FindControl("bldgzip");
    cell = ((GridEditFormItem)txtbx.NamingContainer).EditFormCell;
    validZip.ControlToValidate = txtbx.ID;
    validZip.ErrorMessage = "only [0-9] and '-' are allowed";
    validZip.ValidationExpression = @"^\d{5}(-\d{4})?$";
    validZip.ForeColor = System.Drawing.Color.Red;
    cell.Controls.Add(validZip);
    // End Test Zip
 
    validZip.Validate();
  }

3 Answers, 1 is accepted

Sort by
0
Helen
Top achievements
Rank 1
answered on 20 Nov 2013, 04:32 PM

I thought something like txtbx.Parent would get me the cell that contains the textbox for validation and then the validation message would just be in the same cell.  However, it seems the message was placed "outside" of the table I built in the FormTemplate.  Anyone has any idea how I can get the right table cell? I have attached a screenshot of what I was describing.

GridEditFormItem formitem = e.Item as GridEditFormItem;
TextBox txtbx = formitem.FindControl("bldgzip") as TextBox;
TableCell cell = (TableCell) txtbx.Parent;
0
Steve Lassanske
Top achievements
Rank 1
answered on 20 Nov 2013, 05:39 PM
I don't know if this helps, but one way that I'm accessing a cell so that I can apply a custom tooltip control for the current row in the ItemDataBound event is to wrap my link (cell contents) in a panel, and in the event search for that panel container and apply the tooltip to that container

<telerik:GridTemplateColumn UniqueName="RegistrationNumber" DataField="RegistrationNumber" HeaderText="Reg Number" AllowFiltering="true" SortExpression="RegistrationNumber" FilterControlWidth="50px" HeaderStyle-Width="80px" AutoPostBackOnFilter="true" CurrentFilterFunction="Contains">
    <ItemTemplate>
        <asp:Panel ID="pnlRegistrationNumber" runat="server">
            <a href="#" title="Shipment Info" onclick="openRadShipmentWindow('<%#DataBinder.Eval(Container.DataItem,"OrderID")%>', '<%#DataBinder.Eval(Container.DataItem,"RegistrationNumber")%>'); return false;">
                <%#DataBinder.Eval(Container.DataItem, "RegistrationNumber")%></a>
        </asp:Panel>
    </ItemTemplate>
</telerik:GridTemplateColumn>
Control target2 = e.Item.FindControl("pnlRegistrationNumber");
if (!Object.Equals(target2, null))
{
    if (!Object.Equals(this.RadToolTipManager2, null))
    {
        //Add the button (target) id to the tooltip manager
        this.RadToolTipManager2.TargetControls.Add(target2.ClientID, (e.Item as GridDataItem).GetDataKeyValue("OrderID").ToString(), true);
 
    }
}
0
Helen
Top achievements
Rank 1
answered on 20 Nov 2013, 06:18 PM
Hi Steve,

Thank you so much!! I've been struggling for 2 days. That's a neat trick to resolve this problem. The message is now sitting where I want it to be. I really appreciate your help!

Regard,

Helen
Tags
Grid
Asked by
Helen
Top achievements
Rank 1
Answers by
Helen
Top achievements
Rank 1
Steve Lassanske
Top achievements
Rank 1
Share this question
or