Wednesday 11 June 2008

Learning Log 3: Invalid postback or callback argument.

I've never understood what this error was all about. A lot of posts on the internet just advise that you turn off EventValidation but this is just a cop out if you ask me.

Recently a colleague of mine fixed the issue and i think this was the offending code:

protected void gvSubscriberList_RowDataBound(object sender, GridViewRowEventArgs e)

{

if (e.Row.RowType == DataControlRowType.DataRow)

{

Persons suby = (Person)e.Row.DataItem;

if (suby != null)

{

Button button = (Button)e.Row.FindControl("btnDelete");

if (button != null)

{

button.OnClientClick = "return confirm('Are you sure?');";

}



}

}

}


That code was replaced with:


// override default 'button-like' behaviour to avoid invalid validation errors

Button button = (Button)e.Row.FindControl("btnDelete");

if (button!= null)

{

button.OnClientClick = "if(confirm('Are you sure?'))javascript:__doPostBack('" + gridVuiew.UniqueID + "','Delete$" + e.Row.RowIndex.ToString() + "');return false;";

}



Button updateButton = (Button)e.Row.FindControl("ctl01");

if (updateButton != null)

{

updateButton.OnClientClick = "javascript:__doPostBack('" + gridView.UniqueID + "','Update$" + e.Row.RowIndex.ToString() + "');return false;";

}

No comments:

Post a Comment