• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 256
  • Last Modified:

validation happening in Edit mode..

validation occuring in the controls outside the datagrid .

Actually, i have a datagrid on the same page where am am doin edit function . aftr making changes when clicked update button , am finding validations which r occurin in other controls on that page . which should not happen ...

Thanks ..Lukin for help...
<table class="main_tbl" style="left: 23px; position: relative; top: 49px; z-index: 102;">
            <tr>
                <td style="width: 100px">
                    Select City</td>
                <td style="width: 100px">
                    <asp:DropDownList ID="DropDownList1" runat="server" DataSourceID="SqlDataSource1"
                        DataTextField="city" DataValueField="cid" Style="position: relative" Width="110px" AppendDataBoundItems="True">
                        <asp:ListItem Value="ci">Select City</asp:ListItem>
                    </asp:DropDownList><asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:tonivtreepConnectionString %>"
                        SelectCommand="SELECT [cid], [city] FROM [citytable]"></asp:SqlDataSource>
                </td>
                <td style="width: 100px">
                    <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="DropDownList1"
                        ErrorMessage="Select City" InitialValue="ci" Style="position: relative"></asp:RequiredFieldValidator></td>
            </tr>
            <tr>
                <td style="width: 100px">
                    Enter Recipe<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server"
                        ControlToValidate="TextBox1" ErrorMessage="*" Style="position: relative"></asp:RequiredFieldValidator></td>
                <td style="width: 100px">
                    <asp:TextBox ID="TextBox1" runat="server" Style="position: relative"></asp:TextBox></td>
                <td style="width: 100px">
                </td>
            </tr>
            <tr>
                <td style="width: 100px">
                </td>
                <td style="width: 100px">
                    &nbsp;<asp:ImageButton ID="ImageButton1" runat="server" ImageUrl="~/images/Add_Recipe.gif"
                        OnClick="ImageButton1_Click" Style="position: relative" /></td>
                <td style="width: 100px">
                    <asp:Label ID="Label1" runat="server" Style="position: relative" Width="69px"></asp:Label></td>
            </tr>
        </table>
        &nbsp;&nbsp;
        <asp:DataGrid ID="DataGrid1" runat="server" AllowPaging="True"  AutoGenerateColumns="False"
            OnPageIndexChanged="DataGrid1_PageIndexChanged" Style="z-index: 103; left: 421px;
            position: absolute; top: 102px" BackColor="White" BorderColor="#3366CC" BorderStyle="None" BorderWidth="1px" CellPadding="4" OnCancelCommand="DataGrid1_CancelCommand" OnDeleteCommand="DataGrid1_DeleteCommand" OnEditCommand="DataGrid1_EditCommand" OnUpdateCommand="DataGrid1_UpdateCommand" DataKeyField="hid" >
            <Columns>
                <asp:BoundColumn DataField="city" HeaderText="City" ReadOnly="True"></asp:BoundColumn>
                <asp:TemplateColumn HeaderText="Recipe">
                    <EditItemTemplate>
                        <asp:TextBox ID="TextBox2" Text='<%# Bind("recipe") %>' runat="server" Style="position: relative"></asp:TextBox>
                    </EditItemTemplate>
                    <ItemTemplate>
                        <asp:Label ID="Label2" Text='<%# Bind("recipe") %>' runat="server" Style="position: relative" ></asp:Label>
                    </ItemTemplate>
                </asp:TemplateColumn>
                <asp:EditCommandColumn CancelText="Cancel" EditText="Edit" HeaderText="Modify" UpdateText="Save">
                </asp:EditCommandColumn>
                <asp:ButtonColumn CommandName="Delete" Text="Delete"></asp:ButtonColumn>
            </Columns>
            <FooterStyle BackColor="#99CCCC" ForeColor="#003399" />
            <SelectedItemStyle BackColor="#009999" Font-Bold="True" ForeColor="#CCFF99" />
            <PagerStyle BackColor="#99CCCC" ForeColor="#003399" HorizontalAlign="Left" Mode="NumericPages" />
            <ItemStyle BackColor="White" ForeColor="#003399" />
            <HeaderStyle BackColor="#003399" Font-Bold="True" ForeColor="#CCCCFF" />
        </asp:DataGrid>

Open in new window

0
Rajar Ahmed
Asked:
Rajar Ahmed
5 Solutions
 
GreymanMSCCommented:
You do not have any ValidationGroup settings, so all validation happens at the page level.  There's no way to distinguish between items after all.

Set the ValidationGroup attribute on all controls, validators, and relevant command buttons to the same name.
0
 
keustermansCommented:
This will do the trick.

<asp:Button id=UpdateButton runat=server Text=Update CausesValidation=False />

Enjoy,
Marcus
0
 
kaylanreilorCommented:
If you want to quickly turn the validation off caused by other controls, set their CausesValidation property to false, like this button for example:
<asp:Button ID="btnTomorrow" runat="server" Text="Tomorrow"
        onclick="btnTomorrow_Click" CausesValidation=false />

Else, if you want to investigate further to understand what's occuring and if it has to do with your validator, let's set a custom error message with the ErrorMessage property of those validator. Thus in debug I suppose you'll be able to get a better idea of what's going on.
0
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

 
GreymanMSCCommented:
EG: Use MainGroup for the RequiredFieldValidators and ImageButton in the table, and DataGrid1Group for  the EditCommandColumn in the DataGrid.
<table class="main_tbl" style="left: 23px; position: relative; top: 49px; z-index: 102;">
            <tr>
                <td style="width: 100px">
                    Select City</td>
                <td style="width: 100px">
                    <asp:DropDownList ID="DropDownList1" runat="server"
                        DataSourceID="SqlDataSource1"
                        DataTextField="city" DataValueField="cid" 
                        Style="position: relative" Width="110px" 
                        ValidationGroup="MainGroup"
                        AppendDataBoundItems="True">
                        <asp:ListItem Value="ci">Select City</asp:ListItem>
                    </asp:DropDownList><asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:tonivtreepConnectionString %>"
                        SelectCommand="SELECT [cid], [city] FROM [citytable]"></asp:SqlDataSource>
                </td>
                <td style="width: 100px">
                    <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="DropDownList1" ValidationGroup="MainGroup"
                        ErrorMessage="Select City" InitialValue="ci" Style="position: relative"></asp:RequiredFieldValidator></td>
            </tr>
            <tr>
                <td style="width: 100px">
                    Enter Recipe<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server"
                        ValidationGroup="MainGroup"
                        ControlToValidate="TextBox1" ErrorMessage="*" Style="position: relative"></asp:RequiredFieldValidator></td>
                <td style="width: 100px">
                    <asp:TextBox ID="TextBox1" runat="server" Style="position: relative"></asp:TextBox></td>
                <td style="width: 100px">
                </td>
            </tr>
            <tr>
                <td style="width: 100px">
                </td>
                <td style="width: 100px">
                    <asp:ImageButton ID="ImageButton1" runat="server" ImageUrl="~/images/Add_Recipe.gif"
                        ValidationGroup="MainGroup"
                        OnClick="ImageButton1_Click" Style="position: relative" /></td>
                <td style="width: 100px">
                    <asp:Label ID="Label1" runat="server" Style="position: relative" Width="69px"></asp:Label></td>
            </tr>
        </table>
        &nbsp;&nbsp;
        <asp:DataGrid ID="DataGrid1" runat="server" AllowPaging="True"  AutoGenerateColumns="False"
            OnPageIndexChanged="DataGrid1_PageIndexChanged" Style="z-index: 103; left: 421px;
            position: absolute; top: 102px" BackColor="White" BorderColor="#3366CC" BorderStyle="None" BorderWidth="1px" CellPadding="4" OnCancelCommand="DataGrid1_CancelCommand" OnDeleteCommand="DataGrid1_DeleteCommand" OnEditCommand="DataGrid1_EditCommand" OnUpdateCommand="DataGrid1_UpdateCommand" DataKeyField="hid" 
>
            <Columns>
                <asp:BoundColumn DataField="city" HeaderText="City" ReadOnly="True"></asp:BoundColumn>
                <asp:TemplateColumn HeaderText="Recipe">
                    <EditItemTemplate>
                        <asp:TextBox ID="TextBox2" Text='<%# Bind("recipe") %>' runat="server" Style="position: relative"></asp:TextBox>
                    </EditItemTemplate>
                    <ItemTemplate>
                        <asp:Label ID="Label2" Text='<%# Bind("recipe") %>' runat="server" Style="position: relative" ></asp:Label>
                    </ItemTemplate>
                </asp:TemplateColumn>
                <asp:EditCommandColumn CancelText="Cancel" EditText="Edit" HeaderText="Modify" UpdateText="Save" ValidationGroup="DataGrid1Group">
                </asp:EditCommandColumn>
                <asp:ButtonColumn CommandName="Delete" Text="Delete"></asp:ButtonColumn>
            </Columns>
            <FooterStyle BackColor="#99CCCC" ForeColor="#003399" />
            <SelectedItemStyle BackColor="#009999" Font-Bold="True" ForeColor="#CCFF99" />
            <PagerStyle BackColor="#99CCCC" ForeColor="#003399" HorizontalAlign="Left" Mode="NumericPages" />
            <ItemStyle BackColor="White" ForeColor="#003399" />
            <HeaderStyle BackColor="#003399" Font-Bold="True" ForeColor="#CCCCFF" />
        </asp:DataGrid>

Open in new window

0
 
GreymanMSCCommented:
Ah, yes.  The EdotCommandColumn can be set to not cause validation.  Which, I guess, will be simpler unless you wish to add validation later.
<asp:EditCommandColumn CancelText="Cancel" EditText="Edit" 
    HeaderText="Modify" UpdateText="Save" CauseValidation="False">
</asp:EditCommandColumn>

Open in new window

0
 
Rajar AhmedConsultantAuthor Commented:
thanks for alllll........
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now