DataGrid Column's Validator fires when Column is not visible

Last post 12-29-2006 5:33 PM by ZLA. 2 replies.

Sort Posts:

  • DataGrid Column's Validator fires when Column is not visible

    12-29-2006, 12:41 PM
    • Loading...
    • ZLA
    • Joined on 06-22-2004, 11:28 AM
    • Posts 713

    I have a template column that includes a dropdownlist and requiredfieldvalidator:

          <asp:DataGrid id="dgEdit" runat="server" CssClass="CostTable" GridLines="none"
              AutoGenerateColumns="false"
            >
            <Columns>
              <asp:TemplateColumn ItemStyle-Width="335px" >
                <ItemTemplate>
                  <asp:DropDownList ID="cboCostItem" runat="server" Autopostback="true" />
                  <asp:RequiredFieldValidator ID="vreqCostItem" runat="server" ControlToValidate="cboCostItem" 
                      Text="*" Display="None" EnableClientScript="false" ErrorMessage="Cost Item is required."
                  />
                  <asp:Textbox cssClass="txt" ID="txtOtherItem" runat="server" MaxLength="50" />
                </ItemTemplate>
              </asp:TemplateColumn>
              <asp:TemplateColumn HeaderText="Cost" ItemStyle-Width="75px" >
                <ItemTemplate>
                  <asp:Label cssClass="lbl lblBox"  ID="lblCost" runat="server" Width="75px" />
                </ItemTemplate>
              </asp:TemplateColumn>
            </Columns>
          </asp:DataGrid>
    

     In ItemDataBound, I sometimes make the first column hidden:

       Protected Sub dgEdit_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles dgEdit.ItemDataBound
          Select Case e.Item.ItemType
             Case ListItemType.Item
                Dim sCostTypeCode As String = DataBinder.GetPropertyValue(e.Item.DataItem, "CostTypeCode")
                Me.dgEdit.Columns(0).Visible = (sCostTypeCode = "EXP")
             Case Else
          End Select
       End Sub
    

     

    When the column is hidden, though, vreqCostItem still fires when I validate the page. I thought invisible validators didn't fire. Any suggestions? Thanks in advance. -- ZLA

    Filed under: ,
  • Re: DataGrid Column's Validator fires when Column is not visible

    12-29-2006, 4:29 PM
    • Loading...
    • Darmark
    • Joined on 09-11-2003, 11:09 AM
    • Long Island, NY
    • Posts 529

    Well, to make sure it doesn't fire when the column is hidden, find the validator and set the 'Enable' property to false.

     

    Darmark

    Mark as Answer, if this reply answers your post.
  • Re: DataGrid Column's Validator fires when Column is not visible

    12-29-2006, 5:33 PM
    • Loading...
    • ZLA
    • Joined on 06-22-2004, 11:28 AM
    • Posts 713
    I went ahead and already did that but aren't validators supposed to be "smarter" than that? Or does a hidden column still leave the column's controls as 'visible' and therefore the validator doesn't notice? Doesn't the visibility walk up the control chain so that controls inside panels with visible = false won't trigger their validators?
Page 1 of 1 (3 items)
Microsoft Communities
Page view counter