I have ajaxed radgrid component (with EditFormSettings) that need to postback on specific case.
The radgrid contains GridButtonColumn object when clicked it creates excel file and send it through httpresponse.
I thought I solve the problem by register the buttons at radgrid ItemCreated event
this is the code:
protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e) |
{ |
//register all buttons that exports excel files |
if (e.Item is GridDataItem) |
{ |
GridDataItem gridItem = e.Item as GridDataItem; |
try |
{ |
TableCell buttonTc = gridItem["exportButton"]; |
ControlCollection controls = buttonTc.Controls; |
foreach (Control button in controls) |
{ |
ScriptManager.GetCurrent(this.Page).RegisterPostBackControl(button); |
} |
} |
catch (Exception) { return; } |
} |
} |
it works perfectly till someone opens the EditFormSettings (by clicking on a row).
after that, it looks like the buttons were somehow unregistered and became ajax again, which means no excel file will open.
Is there a solution for this?
thanks.
8 Answers, 1 is accepted
The following documentation explains how to perform postback for ajaxified controls. I hope that will help you.
Forcing postback
Thanks,
Princy.
But It didn't help me (maybe if you can elaborate).
I don't understand why after the user fires an ajax event inside the grid, the buttons becomes ajax instead of postback...?
thanks
If you have export buttons in your edit form that need to postback, you need to also find these buttons using ItemCreated and register them as postback controls:
protected
void
RadGrid1_ItemCreated(
object
sender, GridItemEventArgs e)
{
//register all buttons that exports excel files
if
(e.Item
is
GridEditableItem)
{
GridEditableItem gridItem = e.Item
as
GridEditableItem;
try
{
TableCell buttonTc = gridItem[
"exportButton"
];
ControlCollection controls = buttonTc.Controls;
foreach
(Control button
in
controls)
{
ScriptManager.GetCurrent(
this
.Page).RegisterPostBackControl(button);
}
}
catch
(Exception) {
return
; }
}
}
The difference between the above snippet and your piece of code is that we check for GridEditableItem which also includes the edit forms. We thus find export buttons in the edit form too.
If this is not the case with your scenario, consider removing the try - catch block to see if you get any exceptions and if they don't tell you something related to this issue.
Best wishes,
Veli
the Telerik team
My issue is not inside the edit form, the buttons that needs to be postback are the GridButtonColumn which belongs to the RadGrid.
This is my RadGrid, the last column, exportButton, is the one I have trouble convert to full post back.
<telerik:RadGrid ID="activityRadGrid" runat="server" width="100%" GridLines="None" | |
PageSize="10" AllowPaging="True" DataSourceID="SqlDataSource1" AutoGenerateColumns="False" | |
OnItemCommand="activityRadGrid_itemCommand" OnItemCreated="RadGrid1_ItemCreated" | |
OnItemDataBound="activityRadGrid_ItemDataBound" | |
AllowMultiRowSelection="false" AllowFilteringByColumn="True"> | |
<PagerStyle Mode="NextPrevNumericAndAdvanced" /> | |
<SelectedItemStyle BackColor="#f6faf9" /> | |
<MasterTableView Name="masterTableView" Dir="RTL" GroupLoadMode="Server" | |
DataKeyNames="ID" DataSourceID="SqlDataSource1" | |
AllowSorting="true" AllowMultiColumnSorting="true" TableLayout="Auto"> | |
<HeaderStyle HorizontalAlign="Center" BorderStyle="Groove"/> | |
<ItemStyle HorizontalAlign="Center" /> | |
<Columns> | |
<telerik:GridEditCommandColumn UniqueName="EditCommandColumn" EditText="פתח" Visible="false"> | |
</telerik:GridEditCommandColumn> | |
<telerik:GridBoundColumn DataField="ID" HeaderText="ID" UniqueName="ID" Visible="false" > | |
</telerik:GridBoundColumn> | |
<telerik:GridBoundColumn DataField="source" HeaderText="source" UniqueName="source" Visible="false" > | |
</telerik:GridBoundColumn> | |
<telerik:GridBoundColumn DataField="source_heb" HeaderText="מקור נתונים" UniqueName="source_heb" ItemStyle-HorizontalAlign="Right" > | |
</telerik:GridBoundColumn> | |
<telerik:GridBoundColumn DataField="job_id" HeaderText="מס' תהליך" UniqueName="job_id" FilterControlWidth="30px"> | |
</telerik:GridBoundColumn> | |
<telerik:GridDateTimeColumn DataField="MATCHER_LAST_END_DATE" HeaderText="תאריך סיום הצלבה" UniqueName="MATCHER_LAST_END_DATE" | |
DataFormatString="{0:dd/MM/yy}" PickerType="DatePicker"> | |
<HeaderStyle Width="120px" /> | |
</telerik:GridDateTimeColumn> | |
<telerik:GridBoundColumn DataField="MATCHER_ACCUM_RECORDS" HeaderText="סהכ רשומות שעברו הצלבה" AllowFiltering="false" | |
UniqueName="MATCHER_ACCUM_RECORDS"> | |
</telerik:GridBoundColumn> | |
<telerik:GridBoundColumn DataField="ACTIVITY_ACCUM_NUMOFDICOVERY" HeaderText="סהכ גילויים שנוצרו" UniqueName="ACTIVITY_ACCUM_NUMOFDICOVERY" AllowFiltering="false"> | |
</telerik:GridBoundColumn> | |
<telerik:GridBoundColumn DataField="ACTIVITY_ACCUM_NUMOFRECLAMTION" HeaderText="סהכ טיובים שנוצרו" AllowFiltering="false" | |
UniqueName="ACTIVITY_ACCUM_NUMOFRECLAMTION"> | |
</telerik:GridBoundColumn> | |
<telerik:GridBoundColumn DataField="ACTIVITY_STATUS" HeaderText="סטטוס פעילות" ItemStyle-Width="15px" AllowFiltering="false" | |
UniqueName="ACTIVITY_STATUS"> | |
</telerik:GridBoundColumn> | |
<telerik:GridButtonColumn Text="צור קובץ" headerText="תוצאות הצלבה" HeaderButtonType="LinkButton" UniqueName="exportButton" | |
CommandName="Export"> | |
</telerik:GridButtonColumn> | |
</Columns> | |
<EditFormSettings UserControlName="controls\ActivityInnerControl.ascx" EditFormType="WebUserControl"> | |
<EditColumn UniqueName="EditCommandColumn1"> | |
</EditColumn> | |
</EditFormSettings> | |
</MasterTableView> | |
<EditItemStyle BackColor="#e8f1f0" BorderStyle="Double"></EditItemStyle> | |
<SelectedItemStyle BorderStyle="None"></SelectedItemStyle> | |
<ClientSettings> | |
<ClientEvents OnRowClick="RowDblClick" /> | |
</ClientSettings> | |
<GroupingSettings GroupByFieldsSeparator="Status_text" ShowUnGroupButton="true"/> | |
</telerik:RadGrid> | |
Thanks again.
Sorry for misunderstanding you, then. The scenario that you describe to be using seems to work OK at my side, though. Attaching a test page you can run locally too. I find the export button in the export column and register it as a postback control through the ScriptManager.
Greetings,
Veli
the Telerik team
(Sometimes I feel like running around in circles,
I wasn't thinking ahead, Now that they are standard buttons, I wont see the "Loading" logo :( )
Hello Veli,
This fixed it for me as well.
After I modified my datasource, the grid refreshed as expected, but the export button quit working again (parsing error). So initial loading of the radGrid was okay, but refreshing radGrid data killed it. I even noticed the ITemCreated event fired again to register postback.
Thanks for any feedback.
Steve
protected void RadGridTR_List_ItemCreated(object sender, GridItemEventArgs e)
{
if (e.Item is GridDataItem)
{
if (e.Item is GridDataItem)
{
GridDataItem item = (GridDataItem)e.Item;
ImageButton exportButton = (ImageButton)item["Download"].Controls[0];
ScriptManager.GetCurrent(Page).RegisterPostBackControl(exportButton);
}
}
}
Hi Steve,
Thanks for sharing your experience with our community.
You can also check the javascript approach provided here:
Regards,
Eyup
Progress Telerik