Click here to Skip to main content
Rate this: bad
Please Sign up or sign in to vote.
See more: ASP.NET
I am trying to learn ASPX and am doing a web site (studying purpose)
I have an employee list in grid view when a name in the list is clicked I must pass the value to db and display the details in a separate page.
I did this by using this piece of code
LinkButton lnkCustomerID = sender as LinkButton;
string strCustomerID = lnkCustomerID.CommandArgument;
Response.Redirect("EmployeeDetail.aspx?Parameter=" + strCustomerID);
It worked fine.
In the detail page i am showing the details in another grid and I did this using the code below
 SqlCommand cmdCustomerDetails = new SqlCommand("GetEmployee", sqlConnect);
             cmdCustomerDetails.CommandType = CommandType.StoredProcedure;
             cmdCustomerDetails.Parameters.AddWithValue("@ID", employeeId);
             if (sqlConnect.State == ConnectionState.Closed)
             //Create DataReader to read the record
             SqlDataReader dReader = cmdCustomerDetails.ExecuteReader();
             GridView2.DataSource = dReader;
It worked also, but when I try to update values by clicking the Update Button which is an Item Template as shown
<asp:GridView ID="GridView2" runat="server" CellPadding="4" ForeColor="#333333" GridLines="None"
            <asp:TemplateField HeaderText="Name">
                    <asp:TextBox ID="txtName" runat="server" Text='<%# Eval("name")%>'></asp:TextBox>
                    <asp:RequiredFieldValidator ID="rqdfldName" runat="server" ErrorMessage="Name Cannot Be Empty"
                        ViewStateMode="Disabled" ControlToValidate="txtName" ValidationGroup="Update"></asp:RequiredFieldValidator>
            <asp:TemplateField HeaderText="Age">
                    <asp:TextBox ID="txtAge" runat="server" Text='<%# Eval("age")%>'></asp:TextBox>
            <asp:TemplateField HeaderText="Address">
                    <asp:TextBox TextMode="MultiLine" ID="txtAddress" runat="server" Text='<%# Eval("address")%>'></asp:TextBox>
                    <asp:Button ID="btnUpdate" runat="server" Text="Update" ValidationGroup="Update"
                        CommandArgument='<%#Eval("id") %>' OnClick="btnUpdate_Click" />
        <AlternatingRowStyle BackColor="White" />
        <EditRowStyle BackColor="#7C6F57" />
        <FooterStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
        <HeaderStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
        <PagerStyle BackColor="#666666" ForeColor="White" HorizontalAlign="Center" />
        <RowStyle BackColor="#E3EAEB" />
        <SelectedRowStyle BackColor="#C5BBAF" Font-Bold="True" ForeColor="#333333" />
        <SortedAscendingCellStyle BackColor="#F8FAFA" />
        <SortedAscendingHeaderStyle BackColor="#246B61" />
        <SortedDescendingCellStyle BackColor="#D4DFE1" />
        <SortedDescendingHeaderStyle BackColor="#15524A" />
I am getting this error
Invalid postback or callback argument.  Event validation is enabled using <pages enableeventvalidation="true" /> in configuration or <%@ Page EnableEventValidation="true" %> in a page.  For security purposes, this feature verifies that arguments to postback or callback events originate from the server control that originally rendered them.  If the data is valid and expected, use the ClientScriptManager.RegisterForEventValidation method in order to register the postback or callback data for validation.
Can anyone please help me out
I was able to overcome that error by setting the property of that page to false
like this
<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPage.master" EnableEventValidation="false" AutoEventWireup="true" CodeFile="EmployeeDetail.aspx.cs" Inherits="EmployeeDetail" %>
But when I click the update button and find the values of the controls I am not getting updated values
int empID;
        string age, address, name;
        Button btnUpdateUser = sender as Button;
        TextBox tbName, tbAge, tbAddress;
        SqlConnection sqlConnect;
            tbName = (TextBox)GridView2.Rows[0].FindControl("txtName");
            tbAge = (TextBox)GridView2.Rows[0].FindControl("txtAge");
            tbAddress = (TextBox)GridView2.Rows[0].FindControl("txtAddress");
            sqlConnect = new SqlConnection("server=WINNER-PC\\SQLEXPRESS;integrated security=true;initial catalog=Test");
            if (sqlConnect.State == ConnectionState.Closed)
            empID = Convert.ToInt32(btnUpdateUser.CommandArgument);
            name = tbName.Text;
            age = tbAge.Text;
            address = tbAddress.Text;
            SqlCommand sqlCommand = new SqlCommand("UpdateEmployee", sqlConnect);
            sqlCommand.CommandType = CommandType.StoredProcedure;
            sqlCommand.Parameters.AddWithValue("@ID", empID);
            sqlCommand.Parameters.AddWithValue("@Name", name);
            sqlCommand.Parameters.AddWithValue("@Age", age);
            sqlCommand.Parameters.AddWithValue("@Address", address);
            Response.Redirect("Employees.aspx", false);
        catch (Exception ex)
            throw ex;

When both the grid view were in same page i was able to update , but when i moved the second grid to a new page updation is not working .. Please help me out
Posted 7-Dec-12 20:55pm
Edited 7-Dec-12 22:17pm

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Arjun Menon U.K at 8-Dec-12 3:22am
Why i am nt getting the entered values from textbox while updating?
Arjun Menon U.K at 8-Dec-12 4:05am
Is there something wrong with the way am doing??

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 389
1 Sergey Alexandrovich Kryukov 362
2 CPallini 130
3 Abdul Samad KP 125
4 Richard MacCutchan 110
0 OriginalGriff 6,249
1 Sergey Alexandrovich Kryukov 5,680
2 CPallini 4,850
3 George Jonsson 3,454
4 Gihan Liyanage 2,522

Advertise | Privacy | Mobile
Web03 | 2.8.140916.1 | Last Updated 9 Dec 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100