?
Solved

Range validator not preventing row updating operation in gridview

Posted on 2009-04-19
3
Medium Priority
?
890 Views
Last Modified: 2012-06-27
I have a range validator for a textbox in a gridview template field. It checks that the textbox has an integer in specfic range. In the associated gridview_rowupdating code I have an "if" statement based on "page.isvalid". The code inside the if statement is being executed even though the page is not valid due to not having an appropriate integer in the textbox.
<asp:GridView ID="gvGames" runat="server"
        AllowSorting ="True"
        AutoGenerateColumns="False"
        AutoGenerateEditButton="True"
        OnRowEditing="gvGames_RowEditing"         
        OnRowCancelingEdit="gvGames_RowCancelingEdit" 
        OnRowUpdating="gvGames_RowUpdating"
        OnPageIndexChanging="gvGames_PageIndexChanging"
        CellPadding="4" 
        GridLines="None" Width="728px" style="font-size: medium" > 
        <Columns>
           <asp:CommandField ShowDeleteButton="True" ValidationGroup="ValidScore" />
           <asp:TemplateField HeaderText="Date" SortExpression="Date">
                    <EditItemTemplate>
                        <asp:Label ID="Labe21" runat="server" Text='<%# Bind("Date", "{0:MMM d, yyyy (ddd)}") %>'></asp:Label>
                    </EditItemTemplate>
                    <ItemTemplate>
                        <asp:Label ID="Label22" runat="server" Text='<%# Bind("Date", "{0:MMM d, yyyy (ddd)}") %>'></asp:Label>
                    </ItemTemplate>
           </asp:TemplateField>
           <asp:TemplateField HeaderText="VisitingTeam" SortExpression="VisitingTeam">
                    <EditItemTemplate>
                        <asp:Label ID="Labe23" runat="server" Text='<%# Bind("VisitingTeam") %>'></asp:Label>
                    </EditItemTemplate>
                    <ItemTemplate>
                        <asp:Label ID="Label24" runat="server" Text='<%# Bind("VisitingTeam") %>'></asp:Label>
                    </ItemTemplate>
           </asp:TemplateField>
            <asp:TemplateField>
                <EditItemTemplate>
                    <asp:TextBox ID="tbVisScore" runat="server" Height="20px" 
                        Text='<%# Bind("VisitingTeamScore") %>' Width="46px"></asp:TextBox>
                    <br />
                    <asp:RangeValidator ID="rvalVisScore" runat="server" 
                        ControlToValidate="tbVisScore" Display="Dynamic" 
                        ErrorMessage="Must be a positive integer between 0 and 100" ForeColor="#993300" MinimumValue="0" 
                        Type="Integer" MaximumValue="100" ValidationGroup="ValidScore"></asp:RangeValidator>
                </EditItemTemplate>
                <ItemTemplate>
                    <asp:Label ID="Label1" runat="server" Text='<%# Eval("VisitingTeamScore") %>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="HomeTeam" SortExpression="HomeTeam">
                    <EditItemTemplate>
                        <asp:Label ID="Labe25" runat="server" Text='<%# Bind("HomeTeam") %>'></asp:Label>
                    </EditItemTemplate>
                    <ItemTemplate>
                        <asp:Label ID="Label26" runat="server" Text='<%# Bind("HomeTeam") %>'></asp:Label>
                    </ItemTemplate>
           </asp:TemplateField>
            <asp:TemplateField>
                <EditItemTemplate>
                    <asp:TextBox ID="tbHomScore" runat="server" Height="20px" 
                        Text='<%# Bind("HomeTeamScore") %>' Width="46px"></asp:TextBox>
                    <br />
                    <asp:RangeValidator ID="rvalHomScore" runat="server" 
                        ControlToValidate="tbHomScore" Display="Dynamic" 
                        ErrorMessage="Must be a positive integer between 0 and 100" ForeColor="#993300" 
                        MaximumValue="100" MinimumValue="0" Type="Integer" 
                        ValidationGroup="ValidScore"></asp:RangeValidator>
                </EditItemTemplate>
                <ItemTemplate>
                    <asp:Label ID="Label3" runat="server" Text='<%# Eval("HomeTeamScore") %>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
             <asp:TemplateField HeaderText="Result" SortExpression="Result" Visible="False">
                    <EditItemTemplate>
                        <asp:SqlDataSource ID="ResultCatsDataSource" runat="server" ConnectionString="<%$ ConnectionStrings:SQL2005_503839_gamevidenceConnectionString2 %>"
                            
                            SelectCommand="SELECT DISTINCT ResultCatsID, ResultText FROM ResultCats ORDER BY ResultCatsID"></asp:SqlDataSource>
                        <asp:DropDownList ID="DropDownList1" runat="server" DataSourceID="ResultCatsDataSource"
                            DataTextField="ResultText" DataValueField="ResultText" SelectedValue='<%# Bind("Result") %>'>
                        </asp:DropDownList>
                    </EditItemTemplate>
                    <ItemTemplate>
                        &nbsp;<asp:Label ID="Label27" runat="server" Text='<%# Eval("Result") %>'></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
        </Columns>
        <RowStyle BackColor="#FFFBD6" ForeColor="#333333" />
        <SelectedRowStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="Navy" />
        <PagerStyle ForeColor="#333333" HorizontalAlign="Center" BackColor="#FFCC66" />
        <HeaderStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
        <AlternatingRowStyle BackColor="White" />
      </asp:GridView>
 
 
 
    Protected Sub gvGames_RowUpdating(ByVal sender As Object, ByVal e As GridViewUpdateEventArgs)
        'Retrieve the table from the session object.
 
        If Page.IsValid Then
                 < calculations >
        End If
    End Sub

Open in new window

0
Comment
Question by:jat465
  • 2
3 Comments
 
LVL 15

Expert Comment

by:NazoUK
ID: 24179712
You've set a validation group for the validator but the update button won't know to use that validationgroup, hence page.isvalid returns true.
0
 

Author Comment

by:jat465
ID: 24179719
How do I tell the update button to use that validationgroup?
0
 
LVL 15

Accepted Solution

by:
NazoUK earned 1000 total points
ID: 24182687
Add it to your existing commandfield.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
Suggested Courses

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question