Click here to Skip to main content
15,908,173 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi. I Have GridView and I want to make the row selectable . But I have error "EnableEventValidation="true" . How to solve this problem using RegisterForEventValidation ?
C# Net.Framework 2.0
// Button opens grid  
public void FindAdr_click(object sender, EventArgs e)
{
adres_data.SelectParameters.Remove(adres_data.SelectParameters["ul"]);
adres_data.SelectParameters.Add("ul", adr_name.Text.ToString());
adres_data.SelectParameters["ul"].DefaultValue = adr_name.Text.ToString();

 }  
// RowDataBound  
 protected void adrTabl_RowDataBound(object sender, GridViewRowEventArgs e)
        {
    if (e.Row.RowType == DataControlRowType.DataRow)
      {
         if (e.Row.RowType == DataControlRowType.DataRow)
           {
              LinkButton _singleClickButton = (LinkButton)e.Row.Cells[0].Controls[0];
              string _jsSingle = ClientScript.GetPostBackClientHyperlink(_singleClickButton,                      "Select$"  + e.Row.RowIndex);
       e.Row.Style["cursor"] = "hand";
      e.Row.Attributes["onclick"] = _jsSingle;
    e.Row.Attributes["onmouseover"] = "this.style.cursor='pointer';this.style.textDecoration='underline';";
    e.Row.Attributes["onmouseout"] = "this.style.textDecoration='none';";
             }
            }
            }  
        // Select row  
        protected void adrTabl_SelectedIndexChanged(object sender, EventArgs e)
        {
          GridViewRow selectedRow = adrTabl.SelectedRow;
            adres.Text = selectedRow.Cells[1].Text + ",," + selectedRow.Cells[2].Text;
            adresF.Text = selectedRow.Cells[1].Text + ",," + selectedRow.Cells[2].Text;

        }
Posted
Updated 12-Feb-15 20:54pm
v2

1 solution

if you don't need the events on the site to be validated by asp.net 2.0 newely added feature.


Invalid PostBack or CallBack argument error is basically raise because of Event Validation feature. The EventValidation feature is a new feature in ASP.NET 2.0, and provides an additional level of checks to verify that a postback from a control on the client is really from that control and not from someone malicious using something like a cross-site script injection to try and manipulate things. It is part of our overall strategy of increasingly adding security in depth levels to the programming model -- so that developers can be secure by default even if they forget to add security checks of their own.

Now, *Invalid PostBack or CallBack argument error may occur when you are firing click event and the object is rebinding or its properties are changed in Page_Load event or someone is trying to hack into your system with cross site scripting.* Each time .Net Framework render a page then it associate a unique Guid for all the controls. When binding a gridview or repeater, on each databind framework will associate a new guid for the contorl. So every time when you are firing event make sure Page_Load event does not change the control, because if the control changed the it will have a different Guid which have acutally fired the event for postback. Here are some scenario with this error.

1) Invalid Postback or Callback argument in GridView Problem may be: You are binding data in Page_Load event with either Object Data Source or Manual Binding with function call. This will make your GridView bind data on every event fire of any control. When you are firing any GridView command with OnRowCommand, before RowCommand fire your GridView will rebind and all control within it will be assigned to new id. So RowCommand could not get the item which have fired the event. Solution for Invalid Postback or Callback argument in GridView: You can bind your data within this if condition.

C#
if (!IsPostBack)

  {

         //Your code for Bind data

  }



from Here
 
Share this answer
 
v2
Comments
Андрей Голубцов 13-Feb-15 6:13am    
@Avinash-Tiwari-Neo , I make this , make databind in
<asp:GridView DataSourceID="adres_data" >
and add the code

protected override void Render(HtmlTextWriter writer)
{
foreach (GridViewRow r in adrTabl.Rows)
{
if (r.RowType == DataControlRowType.DataRow)
{
ClientScript.RegisterForEventValidation(((LinkButton)r.Cells[0].Controls[0]).UniqueID, "Select$" + r.RowIndex);

}
}

base.Render(writer);
}
but i don't know what i need to add in :
if (!IsPostBack)

{
//What code must be there?

}

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900