Validation message in EditForm

4 posts, 0 answers
  1. Helen
    Helen avatar
    42 posts
    Member since:
    Nov 2013

    Posted 19 Nov 2013 Link to this post

    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();
      }

  2. Helen
    Helen avatar
    42 posts
    Member since:
    Nov 2013

    Posted 20 Nov 2013 Link to this post

    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;
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Steve Lassanske
    Steve Lassanske avatar
    5 posts
    Member since:
    Sep 2007

    Posted 20 Nov 2013 Link to this post

    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);
     
        }
    }
  5. Helen
    Helen avatar
    42 posts
    Member since:
    Nov 2013

    Posted 20 Nov 2013 Link to this post

    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
Back to Top