I’m registering a postback event for each row in an ASP.NET GridView.
protected void gvLRR_RowDataBound(object sender, GridViewRowEventArgs e) {
if (e.Row.RowType == DataControlRowType.DataRow) {
if (cs == null)
cs = Page.ClientScript;
e.Row.Attributes.Add("onclick",
cs.GetPostBackEventReference((GridView)sender, "Select$" + e.Row.RowIndex.ToString()));
}
}
The event that is called upon the user clicking a row is the SelectedIndexChanged of the GridView gvLRR.
PROBLEM:
All of this works just fine so long as I set the page directive EnableEventValidation to false, but if I do not set it to false then the page blows up when the user clicks on a row in the GridView. However, I see this as a bit of a hack, because I shouldn’t have to disable event validation just to get postback events to work when clicking upon a GridView row. So is there a better way to go about doing this? Can I somehow register postback events for a row click and somehow manage to have event validation enabled still?
Thank you in advance for the help.
While searching the net, I found this … click row on gridview and trigger postback c#
HTH 🙂