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

RadGrid Export in MOSS WebPart

1 Answer 87 Views
Sharepoint Integration
This is a migrated thread and some comments may be shown as answers.
Melia
Top achievements
Rank 1
Melia asked on 31 Dec 2008, 07:01 PM
Hi, I have created a dynamic reporting web part that will execute a stored procedure and display the result in a RadGrid.  I have also added the option to export the data to a csv.  Everything works fine in the webpart until the export event is raised.  The file can be opened or saved as expected; however, you can no longer raise any events in the webpart.  Here are the main peices of my webpart:

 

Protected Overrides Sub CreateChildControls()

 

 

Try

 

 

MyBase.CreateChildControls()

 

 

Dim imgClear As New Image

 

 

Dim pbTrigger As New PostBackTrigger

 

pbTrigger.ControlID = btnDownload1.ID

 

'Set up the form for date parameters

 

pnlDates.ID =

"pnlDate" + Me.ID

 

lblBeginDate.CssClass =

"form"

 

lblEndDate.CssClass =

"form"

 

 

'Populate the date fields with the default values

 

txtBeginDate.CssClass =

"content"

 

txtEndDate.CssClass =

"content"

 

btnDownload1.ImageUrl =

"/Style Library/images/download1.gif"

 

btnRetrieve.ImageUrl =

"/Style Library/en-us/custom/retrieve.gif"

 

imgClear.ImageUrl =

"/Style Library/en-us/custom/clear.gif"

 

pnlDates.Controls.Add(lblBeginDate)

pnlDates.Controls.Add(txtBeginDate)

pnlDates.Controls.Add(lblEndDate)

pnlDates.Controls.Add(txtEndDate)

pnlDates.Controls.Add(

New LiteralControl("<div class=""subButton""><a href=""javascript:document.forms[0].reset()"">"))

 

pnlDates.Controls.Add(imgClear)

pnlDates.Controls.Add(

New LiteralControl("</a>"))

 

pnlDates.Controls.Add(btnDownload1)

pnlDates.Controls.Add(btnRetrieve)

pnlDates.Controls.Add(

New LiteralControl("</div><br /><br />"))

 

 

Me.Controls.Add(pnlDates)

 

 

'Set up the radgrid properties

 

oGrid.ID =

"oGrid"

 

oGrid.EnableEmbeddedSkins =

False

 

oGrid.Skin =

"NNG"

 

oGrid.Attributes.Add(

"runat", "server")

 

oGrid.AutoGenerateColumns =

True

 

oGrid.ShowHeader =

True

 

oGrid.PagerStyle.Mode = GridPagerMode.NextPrevAndNumeric

oGrid.PagerStyle.Position = GridPagerPosition.Bottom

 

' Display the download button if enabled

 

btnDownload2.ImageUrl =

"/Style Library/images/download2.gif"

 

pnlExport.ID =

"pnlExport" + Me.ID

 

pnlExport.Controls.Add(

New LiteralControl("<div class=""subButton"">"))

 

pnlExport.Controls.Add(btnDownload2)

pnlExport.Controls.Add(

New LiteralControl("</div><br /><br />"))

 

 

Me.Controls.Add(pnlExport)

 

 

Me.Controls.Add(oGrid)

 

 

Catch ex As Exception

 

 

Dim ctx As HttpContext = HttpContext.Current

 

childException = ex

 

End Try

 

 

End Sub

 

 


Protected
Sub btnDownload_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles btnDownload1.Click, btnDownload2.Click

 

oGrid.ExportSettings.ExportOnlyData =

False

 

oGrid.ExportSettings.IgnorePaging =

True

 

oGrid.ExportSettings.OpenInNewWindow =

True

 

 

If fileName.Length > 0 Then

 

oGrid.ExportSettings.FileName = fileName

 

End If

 

oGrid.MasterTableView.ExportToCSV()

 

End Sub

 



 


 

 

Private Sub CustomReportingWebPart_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.PreRender

 

 

Try

 

 

 

 

 

'We need to see if we should display the date forms fields

 

 

 

 

pnlDates.Visible = useDateParams

 

'If the date parameters are not visible, then we need to display the export panel, otherwise

 

 

 

 

 

' the export button is displayed with the clear and retreive buttons

 

 

 

 

 

If useDateParams Then

 

 

 

 

 

Me.pnlExport.Visible = False

 

 

 

 

 

Else

 

 

 

 

 

Me.pnlExport.Visible = True

 

 

 

 

 

End If

 

 

 

 

oGrid.AllowPaging = enablePaging

oGrid.AllowFilteringByColumn = enableFiltering

oGrid.AllowSorting = enableSorting

oGrid.ClientSettings.Scrolling.AllowScroll = enableScrolling

oGrid.ClientSettings.Scrolling.UseStaticHeaders = enableStaticHeaders

oGrid.PageSize = pageSize

oGrid.Width = Unit.Percentage(100)

 

'Populate the date fields with correct values

 

 

 

 

lblBeginDate.Text = beginDateLabel +

"<br>"

 

 

 

 

lblEndDate.Text =

"<br>" + endDateLabel + "<br>"

 

 

 

 

txtBeginDate.Text = dBeginDate.ToString(

"MM/dd/yyyy")

 

txtEndDate.Text = dEndDate.ToString(

"MM/dd/yyyy")

 

 

'Bind the datasource to get the latest changes

 

 

 

 

oGrid.DataSource = getDatavalues()

oGrid.DataBind()

 

Catch ex As Exception

 

 

Dim ctx As HttpContext = HttpContext.Current

 

childException = ex

 

End Try

 

 

 

 

 

End Sub

 

 

Any ideas on how to resolve this issue?

Thanks!

1 Answer, 1 is accepted

Sort by
0
Sebastian
Telerik team
answered on 06 Jan 2009, 12:43 PM
Hi Melia,

We have received a few reports for this abnormality before and unfortunately this issue seems not to be directly related to our RadGrid control. It appears that changing the response's header in order to output the file will cause any postbacks to stop working. We attached a simple web part in support of this statement.

Luckily, after further investigation the export problem, we found the cause of the behavior. It seems that when the form is submitted, a flag is raised by the WSS framework. Because during exporting the page is not refreshed due to the fact that the response is redirected, this flag never gets cleared. Therefore, a possible workaround will be to clear manually this flag when exporting. This can be accomplished by hooking the exporting button's client event and setting _spFormOnSubmitCalled to false. Similar to this:
 
btn.OnClientClick = "_spFormOnSubmitCalled = false;"

Best regards,
Sebastian
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Tags
Sharepoint Integration
Asked by
Melia
Top achievements
Rank 1
Answers by
Sebastian
Telerik team
Share this question
or