469,928 Members | 1,701 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,928 developers. It's quick & easy.

GridView inside update panel, fun ensues.


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="this.style.cursor='hand'; this.style.background='yellow';" onMouseOut="this.style.background='#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="this.style.cursor='hand'; this.style.background='yellow';" onMouseOut="this.style.background='#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
4 11799
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
9,735 Expert Mod 8TB
I'm glad you solved your problem!
Thanks for sharing the solution :)

Jun 22 '09 #3
There is nothing in that website that is related to my question. Thanks for spamming my post dnanetwork.
Jun 27 '09 #4
9,735 Expert Mod 8TB
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.

Similar topics

reply views Thread by AdonisL81 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.