Hi,
I've created a custom module with a RadGrid in the backed to manage the module's items. I have a LinkButton inside a RadGrid GridTemplateColumn which I use to send a PDF document from a database to the user. I ran into the issue described in this thread:
http://www.telerik.com/community/forums/aspnet/ajax/radgrid-response-binarywrite-asp-net-ajax.aspx
I used the solution suggested in that thread adding an event like this one to the grid page:
This seemed to fix the problem, but then I noticed if I make the grid sortable and I click on a column header to sort the items, then I click on any item's LinkButton, I get again the Sys.WebForms.PageRequestManagerParserErrorException. Same happens if I enable grouping and group the items by any column.
This is the LinkButton codebehind:
Thank you,
Alessio Scalerandi
I've created a custom module with a RadGrid in the backed to manage the module's items. I have a LinkButton inside a RadGrid GridTemplateColumn which I use to send a PDF document from a database to the user. I ran into the issue described in this thread:
http://www.telerik.com/community/forums/aspnet/ajax/radgrid-response-binarywrite-asp-net-ajax.aspx
I used the solution suggested in that thread adding an event like this one to the grid page:
protected
void
RadGrid1_ItemCreated(
object
sender, Telerik.WebControls.GridItemEventArgs e)
{
if
(e.Item
is
GridDataItem)
{
Button btn = (e.Item
as
GridDataItem)[
"TemplateColumn"
].FindControl(
"Button1"
)
as
Button;
ScriptManager1.RegisterPostBackControl(btn);
}
if
(e.Item
is
GridCommandItem)
{
Button btncmd = (e.Item
as
GridCommandItem).FindControl(
"Button2"
)
as
Button;
ScriptManager1.RegisterPostBackControl(btncmd);
}
}
This seemed to fix the problem, but then I noticed if I make the grid sortable and I click on a column header to sort the items, then I click on any item's LinkButton, I get again the Sys.WebForms.PageRequestManagerParserErrorException. Same happens if I enable grouping and group the items by any column.
This is the LinkButton codebehind:
protected
void
ItemsGrid_ItemCommand(
object
sender, Telerik.Web.UI.GridCommandEventArgs e)
{
if
(e.Item.ItemType == GridItemType.Item || e.Item.ItemType == GridItemType.AlternatingItem)
{
Guid candidaturaId =
new
Guid(ItemsGrid.MasterTableView.DataKeyValues[e.Item.ItemIndex][
"ID"
].ToString());
// create a new instance of ContactsManager with default provider
CandidatureManager cm =
new
CandidatureManager();
// get the desired candidatura and set the values of the form
ICandidatura candidatura = cm.GetCandidatura(candidaturaId);
string
ext = Path.GetExtension(candidatura.AllegatoFilename).ToLower();
CustomDownload cd =
new
CustomDownload
{
Filename = candidatura.AllegatoFilename,
MimeType = (ext ==
".pdf"
) ? MediaTypeNames.Application.Pdf :
"application/unknown"
,
Data = candidatura.Allegato.ToArray(),
};
ScriptManager sm = (ScriptManager)Page.FindControl(
"TheScriptManager"
);
Response.ClearHeaders();
Response.ClearContent();
Response.AddHeader(
"Accept-Ranges"
, cd.Data.Length.ToString());
Response.AddHeader(
"Content-Disposition"
,
"attachment;filename="
+ cd.Filename);
Response.ContentType = cd.MimeType;
if
(cd.Data.Length > 0)
Response.BinaryWrite(cd.Data);
Response.End();
}
}
Thank you,
Alessio Scalerandi