0

Please cross referrence to devexpress forum

In ASP.NET WEBFORMS project how do you upon a user clicking a devexpress button and callback control, AFTER HAVING generated the csv stream, push the stream to the browser via the Response object BUT NOT trumping the callback mechanism provided by devexpress???... Here is some code

Imports D5FPX
Imports System.Data.Linq
Imports System.Configuration.ConfigurationManager
Imports System.Data

Partial Class MyFolder_MyUserControl
    Inherits UserControlBase

 Const NINE_NUMERO As Integer = 1
 Const VBA As String = "xyz"
 Const CVS_FORMATTER As String = "{0:F2}"

 Dim realcode As String = "99999"
 Dim mycsv As String
 Dim pc As PersistenceClass

 Protected Sub Page_Init(sender As Object, e As System.EventArgs) Handles Me.Init

      If Not Page.IsCallback Then
           h2.InnerText = UserControlName
      End If

 End Sub

 Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load

 End Sub

 Protected Sub btnDownload_Click(sender As Object, e As System.EventArgs) Handles btnDownload.Click

     'blank

 End Sub

 Prviate Sub DoQuery()

      pc = New xxx.PersistenceClass(ConfigurationManager.ConnectionStrings("xxx").ConnectionString.ToString())

      Dim resultQuery = From vi In pc.dbo.xxx_VWs _
                          Join smv In pc.dbo.v_xxx _
                           On vi.givenKey Equals smv.givenKey _
                           Where (vi.Zone <> 0 And vi.user_fld_6 <> "H") _
                           Select New With {.Field1 = smv.Field1, _
                           .Field2 = smv.givenKey.Trim(), _
                           .AB = IIf(vi.Field3.Trim().Contains("old"), "O", "N"), _
                           .Zone = vi.Zone, _
                           .Zenith = vi.Zenith}

      Dim datatable As New DataTable()

      datatable.Columns.Add("Ninja")
      datatable.Columns.Add("Cowboy")
      datatable.Columns.Add("Soldier")
      datatable.Columns.Add("Worker")
      datatable.Columns.Add("Priest")
      datatable.Columns.Add("Zenith")

      For Each row In resultQuery               
           Dim specialZone As Nullable(Of Decimal) = pc.dbo.xxx_RealZone(NINE_NUMERO, realcode, row.Field2, VBA, Date.Now)

           'check for null return value from scalar db function call
           If specialZone Is Nothing Then
                specialZone = row.Zone
           End If

           Dim formattedZone = String.Format(CVS_FORMATTER, row.Zone)
           Dim formattedSpecZone = String.Format(CVS_FORMATTER, specialZone)
           Dim formattedZenithZone = String.Format(CVS_FORMATTER, row.Zenith)

           'datatable.Rows.Add(row.Field1, row.Field2, row.AB, row.Zone, specialZone, row.Core)
           datatable.Rows.Add(row.Field1, row.Field2, row.AB, formattedZone, formattedSpecZone, formattedZenithZone)
      Next

      mycsv = datatable.ConvertToCSV()

      OutputCsv(mycsv)
 End Sub

 Prviate Sub OutputCsv(csv As String)
      Dim finalByteArray As Byte() = Encoding.ASCII.GetBytes(csv)

      Response.ContentType = "text/csv"
      Response.AddHeader("content-disposition", "attachment;filename=abcdef.csv")
      Response.AddHeader("Content-lenght", finalByteArray.Length.ToString())
      Response.Clear()
      Response.Write(csv)          
      Response.Flush()


 End Sub   

 Protected Sub Callback1_Callback(source As Object, e As    DevExpress.Web.ASPxCallback.CallbackEventArgs) Handles Callback1.Callback

       DoQuery()

 End Sub
End Class

Here is the JavaScript functions for the devexpress button and callback controls...

function btnDownload_Click(s, e) {
 lp1.Show();
 cb1.PerformCallback();
}

function cb1_CallbackComplete(s, e) {
 var mydiv1 = document.getElementById('dv1');
 mydiv1.innerHTML = e.result;
 lp1.Hide();
}
dannyrosalex
  • 1,794
  • 4
  • 16
  • 25
  • The first sentence of your second paragraph seems almost engineered to be hard to understand, and you only accept about half of the answers given to you. Think I'll move on... – Jonathan Wood Dec 20 '12 at 21:51
  • Thanks for cutting me down Jonathan! – dannyrosalex Dec 21 '12 at 16:54
  • Well, you can look at it that way. Or you could review the specifics of my comments and see if you have room to improve. (Especially if you're wondering why you didn't get more help with your question.) – Jonathan Wood Dec 21 '12 at 16:56

0 Answers0