GridView ItemTemplate - Validators not being called

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Mel

    GridView ItemTemplate - Validators not being called

    I have a GridView that is bound to a DataTable. I decided to allow
    the user to change the column data right in the ItemTemplate. Then
    user won't need to click Edit to change the values and then click
    Update to save them because for this application the user will need to
    edit the data in every row so I thought the ItemTemplate would be a
    better solution. However, when I place the controls in my
    ItemTemplate my Validators are not being called at all when they enter
    invalid data. Won't the GridView work this way?

    Here is a small snippet of one item template column:
    <asp:TemplateFi eld HeaderText="Dur ation (days)"
    SortExpression= "Duration">
    <EditItemTempla te>
    </EditItemTemplat e>
    <ItemTemplate >
    <asp:TextBox ID="txtDuration " runat="server" Text='<%#
    Bind("[Duration]") %>' Width="56px" CausesValidatio n="True"
    Wrap="False" ValidationGroup ="AllValidators "></asp:TextBox><br />
    <asp:RequiredFi eldValidator ID="rfvDuration " runat="server"
    ControlToValida te="txtDuration "
    ErrorMessage="E nter a Duration (number of days)."
    SetFocusOnError ="True" Display="Dynami c"
    ValidationGroup ="AllValidators "></asp:RequiredFie ldValidator><br />
    <asp:RangeValid ator ID="rvDuration " runat="server"
    ControlToValida te="txtDuration "
    ErrorMessage="E nter a number between 0 and 365 days."
    MaximumValue="3 65"
    MinimumValue="0 " SetFocusOnError ="True" Display="Dynami c"
    Type="Integer" ValidationGroup ="AllValidators "></asp:RangeValida tor>
    </ItemTemplate>
    <ItemStyle VerticalAlign=" Top" />
    </asp:TemplateFie ld>
  • =?Utf-8?B?YnJ1Y2UgYmFya2Vy?=

    #2
    RE: GridView ItemTemplate - Validators not being called

    the control triggering the postback has to have causes validation set to
    true, and have the validation group set to match your specification.

    -- bruce (sqlwork.com)


    "Mel" wrote:
    I have a GridView that is bound to a DataTable. I decided to allow
    the user to change the column data right in the ItemTemplate. Then
    user won't need to click Edit to change the values and then click
    Update to save them because for this application the user will need to
    edit the data in every row so I thought the ItemTemplate would be a
    better solution. However, when I place the controls in my
    ItemTemplate my Validators are not being called at all when they enter
    invalid data. Won't the GridView work this way?
    >
    Here is a small snippet of one item template column:
    <asp:TemplateFi eld HeaderText="Dur ation (days)"
    SortExpression= "Duration">
    <EditItemTempla te>
    </EditItemTemplat e>
    <ItemTemplate >
    <asp:TextBox ID="txtDuration " runat="server" Text='<%#
    Bind("[Duration]") %>' Width="56px" CausesValidatio n="True"
    Wrap="False" ValidationGroup ="AllValidators "></asp:TextBox><br />
    <asp:RequiredFi eldValidator ID="rfvDuration " runat="server"
    ControlToValida te="txtDuration "
    ErrorMessage="E nter a Duration (number of days)."
    SetFocusOnError ="True" Display="Dynami c"
    ValidationGroup ="AllValidators "></asp:RequiredFie ldValidator><br />
    <asp:RangeValid ator ID="rvDuration " runat="server"
    ControlToValida te="txtDuration "
    ErrorMessage="E nter a number between 0 and 365 days."
    MaximumValue="3 65"
    MinimumValue="0 " SetFocusOnError ="True" Display="Dynami c"
    Type="Integer" ValidationGroup ="AllValidators "></asp:RangeValida tor>
    </ItemTemplate>
    <ItemStyle VerticalAlign=" Top" />
    </asp:TemplateFie ld>
    >

    Comment

    Working...