By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,061 Members | 1,222 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,061 IT Pros & Developers. It's quick & easy.

GridView inside update panel, fun ensues.

P: 39

I have a GridView that I put inside an update panel.
I have a control that attaches to the datasource of the gridview that filters the data, databinds the gridview and then updates the update panel that the gridview is in.

In my page render I put this so I could select a row by just clicking it.

Expand|Select|Wrap|Line Numbers
  1.     protected override void Render(HtmlTextWriter writer)
  2.     {
  3.         foreach (GridViewRow row in GridView1.Rows)
  4.         {
  5.             if (row.RowType == DataControlRowType.DataRow)
  6.             {
  7.                 row.Attributes.Add("onclick", Page.ClientScript.GetPostBackEventReference(GridView1, "Select$" + row.RowIndex.ToString(), true));
  8.             }
  9.         }
  10.         Page.ClientScript.RegisterForEventValidation(GridView1.UniqueID);
  11.         base.Render(writer);
  12.     }
The row select works great on the first render of the page. However when I filter my gridview or just update the update panel my onclick attribute is not rendered in the ajax postback.

First hit of page
Expand|Select|Wrap|Line Numbers
  1. <tr onMouseOver="'hand';'yellow';" onMouseOut="'#FFFFFF';" onclick="__doPostBack('ctl00$ContentPlaceHolder1$CustomControl1$GridView1','Select$0')" style="color:#333333;background-color:White;"><td>mydata</td></tr>
Capture of http ajax post using fiddler
Expand|Select|Wrap|Line Numbers
  1. <tr onMouseOver="'hand';'yellow';" onMouseOut="'#FFFFFF';" style="color:#333333;background-color:White;"><td>mydata</td></tr>
Haaaalp! I'm not sure what is happening. The style attributes I put on in my rowdatabound event. The filter control I'm using does not seem to be the culprit because it is only touching my object datasource. So it must be something going on due my grid being in an update panel. Is there something about Update Panels that remove onclick or prevent the rendering in an ajax postback? I've stepped through and the attribute seems to be added in the Render... I'm at a complete loss. Any ideas???
Jun 18 '09 #1
Share this Question
Share on Google+
4 Replies

P: 39
Ok, to solve this I put
Expand|Select|Wrap|Line Numbers
  1. e.Row.Attributes.Add("onclick", ((GridView)sender).Page.ClientScript.GetPostBackEventReference((GridView)sender, "Select$" + e.Row.RowIndex.ToString(), false)); 
in my OnRowDataBound. I'm not sure why I didn't get the event validation error but whatever it works for now.
Jun 19 '09 #2

Expert Mod 5K+
P: 9,731
I'm glad you solved your problem!
Thanks for sharing the solution :)

Jun 22 '09 #3

P: 39
There is nothing in that website that is related to my question. Thanks for spamming my post dnanetwork.
Jun 27 '09 #4

Expert Mod 5K+
P: 9,731
BiffMaGriff, I've deleted the post since it has no relevant help to your question.
Jun 29 '09 #5

Post your reply

Sign in to post your reply or Sign up for a free account.