This is a migrated thread and some comments may be shown as answers.

RadAjaxManager & RadGrid Dynamic LinkButtons Error

4 Answers 71 Views
Ajax
This is a migrated thread and some comments may be shown as answers.
Coty
Top achievements
Rank 1
Coty asked on 05 Feb 2011, 08:34 PM
Hello,

I have a form with a RadScriptManger, RadAjaxManager, and RadGrid.

One of the columns of the RadGrid loads a dynamic linkbutton that I want to pop-up an Open/Save File Dialogue box.  It works without the RadAjaxManager, but with it I get this error:

Error: Sys.WebForms.PageRequestManagerParserErrorException: The message received from the server could not be parsed. Common causes for this error are when the response is modified by calls to Response.Write(), response filters, HttpModules, or server trace is enabled.

Which is correct, I subscribe each dynamic link button to the following click event that modifies the Response,
Protected Sub onClick(ByVal sender As Object, ByVal e As EventArgs)
  
        Try
  
            Dim NewButton As LinkButton = CType(sender, LinkButton)
  
            Dim con As New SqlClient.SqlConnection(ConfigurationManager.ConnectionStrings("NBOConnectionString").ConnectionString)
            Dim cmd As New SqlClient.SqlCommand("Select Id, NDAId, FileName, [File], FileType FROM NDA_Files Where Id = " & Convert.ToInt32(NewButton.ToolTip), con)
            Dim da As New SqlClient.SqlDataAdapter(cmd)
  
            con.Open()
  
            Dim dt As New Data.DataTable
  
            da.Fill(dt)
  
            For Each row As Data.DataRow In dt.Rows
                With row
  
                    Dim DataFile() As Byte
                    DataFile = .Item("File")
                    HttpContext.Current.Response.Buffer = True
                    HttpContext.Current.Response.ContentType = .Item("FileType")
                    HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment;filename=" & .Item("FileName"))
                    HttpContext.Current.Response.AppendHeader("Content-Length", DataFile.Length.ToString())
                    HttpContext.Current.Response.BinaryWrite(DataFile)
  
                End With
            Next
                    Catc

I searched around and found this article:
http://weblogs.asp.net/leftslipper/archive/2007/02/26/sys-webforms-pagerequestmanagerparsererrorexception-what-it-is-and-how-to-avoid-it.aspx

Towards the bottom of that, there is this solution:
Call ScriptManager.RegisterPostBackControl() and pass in the button in question. This is the best solution for controls that are added dynamically, such as those inside a repeating template.

I didn't see "RegisterPostBackControl()" within the RadScriptManager so I added .NETs script manager and added a section in my RadGridItemDataBound procedure to add the dynamic linkbuttons to this as show below:
For Each Control In e.Item.Controls
                       If CType(Control, Telerik.Web.UI.GridTableCell).Controls.Count > 2 Then
                           If CType(Control, Telerik.Web.UI.GridTableCell).Controls(1).GetType.Name = "LinkButton" Then
                               Dim lnkButton As LinkButton = CType(CType(Control, Telerik.Web.UI.GridTableCell).Controls(1), LinkButton)
                               ScriptManager1.RegisterPostBackControl(lnkButton)
                           End If
                       End If
                   Next

Which finds the LinkButtons and adds them with no errors.....However when I click the linkbutton I still get the error.
Is there any better way to get this functionality?

Either I need to figure out how to exclude the linkbuttons from the AJAX call, or a way to make the pop-up work without using the Response.  Any Ideas?

Thanks,

Coty



4 Answers, 1 is accepted

Sort by
0
Coty
Top achievements
Rank 1
answered on 08 Feb 2011, 12:35 AM
Bump

Going to try a couple things later today but still struggling with this...
0
Pavlina
Telerik team
answered on 09 Feb 2011, 01:05 PM
Hello Coty,

Could you please specify if you are using trial or dev version of the RadControls for ASP.NET AJAX? 

Additionally,  you can try handling the errors with ajax as described here.

Check it out and let me know how it goes.

All the best,
Pavlina
the Telerik team
Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
0
Coty
Top achievements
Rank 1
answered on 10 Feb 2011, 03:25 AM
Dev version Q3 2010 which I think is the latest?

Anways, because I was on a time constraint I pulled out the AJAX functionality for now for certain things as it's not required, it's just nicer.  I may look at adding it later again.

The link I looked at briefly and it is about error handling, are you suggesting to just bypass the script error in some way and it should work?

Thanks,

Coty
0
Pavlina
Telerik team
answered on 10 Feb 2011, 11:15 AM
Hello Coty,

I suggest that you take a look at the following blog post which elaborates on the matter.

Additionally, you can review Hristo Deshev's blog post:
Firewalls breaking ASP.NET AJAX!

Regards,
Pavlina
the Telerik team
Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
Tags
Ajax
Asked by
Coty
Top achievements
Rank 1
Answers by
Coty
Top achievements
Rank 1
Pavlina
Telerik team
Share this question
or