Showing posts with label RadGrid. Show all posts
Showing posts with label RadGrid. Show all posts

Thursday, April 17, 2014

Intermittent PageRequestManagerParserErrorException With Full Postback

I have a project with a bunch of ajaxified Telerik controls within several nested UpdatePanel controls. As part of an Excel export process, I have a button which upon clicking performs a full postback, generates a spreadsheet from a RadGrid, and finally prompts the user to download the file. 

Once in a while, though, the export process would throw the dreaded and unhelpful Sys.WebForms.PageRequestManagerParserErrorException exception.



Eilon Lipton's helpful post gave a handy checklist of things not to do, but in spite of ensuring all the common causes were accounted for, it would still occur occasionally.

I tried implementing a workaround shared by a colleague and thus far it appears to have helped. This involves setting the OnClientClicked event handler of the export button so that it triggers a brief pause prior to initiating the full postback using a client-side Javascript.
function onExportClick(sender, args)
{
     setTimeout(

          function () 
          { 
               __doPostBack(sender.id, "_MyButtonID") 
          }, 
          500
     );   
}

The error itself points you in the right direction, but some more context sure would be nice. Anyway, apparently this script mitigates situations where the Telerik controls are still in the process of being rendered when the full postback is initiated, corrupting the Response header in the process. 




Friday, December 27, 2013

LinkButton OnClick Not Firing After OnClientClick

I worked around an oddball problem where the OnClick event of an ASP LinkButton would not fire following execution of some JavaScript tied to its OnClientClick.

The intent is to enable a row in a Telerik RadGrid to be removed by clicking the corresponding button in the row, and more specifically have a modal confirmation dialog appear to prompt the user to confirm their choice.

Here's markup for the GridTemplateColumn containing the button:
<telerik:GridTemplateColumn HeaderText="Remove" UniqueName="Remove" 
  FilterControlWidth="20">
    <ItemTemplate>
        <div style="cursor: hand;">
            <asp:LinkButton runat="server" ID="_RemoveItem" 
                Name="_RemoveItem" Text=" X " Font-Underline="False" 
                ForeColor="DarkBlue" 
                OnClientClick="confirmAspButton(this, 'Are you sure?'); return false;"
                OnClick="RemoveItemButtonClick" 
                style="font-weight:bold;color:red;">
            </asp:LinkButton>
        </div>
    </ItemTemplate>
    <HeaderStyle Width="55"></HeaderStyle>
</telerik:GridTemplateColumn>

The confirmAspButton function is a little JavaScript which is bound to the OnClientClick method of the LinkButton. If the user clicks OK, the confirmation passes and a postback will occur to execute the code beneath the OnClick method, whereas if they click Cancel the dialog will simply disappear.
     function confirmAspButton(button, message) 
     {
          function aspButtonCallbackFn(arg) 
          {
             if (arg) 
             {
                  window.__doPostBack(button.name, "");
             }
          }
            
          window.radconfirm(message, aspButtonCallbackFn, 330, 120, null, "Confirm");
     }


Seems simple enough, yet for some odd reason, in Internet Explorer 10, the LinkButton brought up the dialog just fine, and although the Cancel button click performed as expected, clicking OK had the same effect as cancel and merely cleared the dialog without executing the underlying code.

I managed to find a workaround via StackOverflow which suggests using a Button rather than a LinkButton. Sure enough, this did the trick, for whatever oddball reason whose particulars I could care less to dive into...