1

How do I register post back control on page load using scriptmanager.registerpostbackcontrol(linkbutton) for each row on the gridview which has paging set to true? The linkbutton is within gridview under templatefield. The code I have is:

foreach (GridViewRow row in GridView1.Rows)
    {
        LinkButton LinkButton = row.FindControl("LinkButton ") as LinkButton ;
        ScriptManager scriptManager = ScriptManager.GetCurrent(this.Page);
        scriptManager.RegisterPostBackControl(LinkButton );
    }

My problem is the linkbutton that shows up on the page at one point is working(it exports to pdf) without issues, but when I go to next page(gridview has paging set to true) . Now when I click on the linkbutton it doesn't work. I get this error.

"0x800a139e - Microsoft JScript runtime error: Sys.WebForms.PageRequestManagerParserErrorException: The message received from the server could not be parsed."

please help. Thank you,

Skyblade
  • 2,354
  • 4
  • 25
  • 44
ZeeProgrammer
  • 195
  • 1
  • 13
  • perhaps this should read `scriptManager.RegisterPostBackControl("LinkButton ") as LinkButton;` – MethodMan Nov 04 '15 at 22:25
  • also why is there a space in the `FindControl(LinkButton ")` use the `Debugger` do not just code and go.. as we say in the programming world.. – MethodMan Nov 04 '15 at 22:27
  • @MethodMan Thanks for the response. ("LinkButton "), the space there was just a typo. and I used LinkButton LinkButton = row.FindControl("LinkButton ") as LinkButton; instead of scriptManager.RegisterPostBackControl("LinkButton ") as LinkButton; because the linkbutton is a part of girdview row. This code is running for the most part without issue but The gridview shows 5 rows at one time and I have to hit next to see other records(paging is set true for my girdview). The linkbuttons in the next set of records fails. If I set the paging to false, everything works fine. – ZeeProgrammer Nov 05 '15 at 14:25
  • you need to probable do something like this if you have an event like this `GridView1_PageIndexChanged(object source, DataGridPageChangedEventArgs e)` inside of there do the following `GridView1.CurrentPageIndex = e.NewPageIndex;` then do the `GridView1.DataSource = your DataTable; then do `GridView1.DataBind();` – MethodMan Nov 05 '15 at 14:51
  • 1
    @MethodMan, thanks for your response. The following linked helped me with my issue. http://stackoverflow.com/questions/4872210/full-postback-triggered-by-linkbutton-inside-gridview-inside-updatepanel – ZeeProgrammer Nov 10 '15 at 14:50

0 Answers0