GridView inside update panel, fun ensues.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • BiffMaGriff
    New Member
    • Aug 2007
    • 39

    GridView inside update panel, fun ensues.

    Hello,

    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.

    Code:
        protected override void Render(HtmlTextWriter writer)
        {
            foreach (GridViewRow row in GridView1.Rows)
            {
                if (row.RowType == DataControlRowType.DataRow)
                {
                    row.Attributes.Add("onclick", Page.ClientScript.GetPostBackEventReference(GridView1, "Select$" + row.RowIndex.ToString(), true));
                }
            }
            Page.ClientScript.RegisterForEventValidation(GridView1.UniqueID);
            base.Render(writer);
        }
    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
    Code:
    <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
    Code:
    <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???
  • BiffMaGriff
    New Member
    • Aug 2007
    • 39

    #2
    Ok, to solve this I put
    Code:
    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.

    Comment

    • Frinavale
      Recognized Expert Expert
      • Oct 2006
      • 9749

      #3
      I'm glad you solved your problem!
      Thanks for sharing the solution :)

      -Frinny

      Comment

      • BiffMaGriff
        New Member
        • Aug 2007
        • 39

        #4
        There is nothing in that website that is related to my question. Thanks for spamming my post dnanetwork.

        Comment

        • Frinavale
          Recognized Expert Expert
          • Oct 2006
          • 9749

          #5
          BiffMaGriff, I've deleted the post since it has no relevant help to your question.

          Comment

          Working...