Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

validation happening in Edit mode..

Posted on 2008-11-10
6
Medium Priority
?
254 Views
Last Modified: 2013-12-17
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
Comment
Question by:Rajar Ahmed
6 Comments
 
LVL 16

Assisted Solution

by:GreymanMSC
GreymanMSC earned 1600 total points
ID: 22928041
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
 
LVL 7

Assisted Solution

by:keustermans
keustermans earned 200 total points
ID: 22928046
This will do the trick.

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

Enjoy,
Marcus
0
 
LVL 13

Assisted Solution

by:kaylanreilor
kaylanreilor earned 200 total points
ID: 22928054
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 quick recovery of individual SharePoint items

Free tool – Veeam Explorer for Microsoft SharePoint, enables fast, easy restores of SharePoint sites, documents, libraries and lists — all with no agents to manage and no additional licenses to buy.

 
LVL 16

Accepted Solution

by:
GreymanMSC earned 1600 total points
ID: 22928069
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
 
LVL 16

Assisted Solution

by:GreymanMSC
GreymanMSC earned 1600 total points
ID: 22928097
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
 
LVL 18

Author Closing Comment

by:Rajar Ahmed
ID: 31515399
thanks for alllll........
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Loops Section Overview
Suggested Courses

810 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