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

Export RadGrid only to email

4 Answers 143 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Daniel
Top achievements
Rank 1
Daniel asked on 07 Apr 2014, 03:09 PM
Hi

I am using RadGrid and I need to export it to email.
I looked in your forums and found this answer:

VB.NET:
01.Private Sub RadGrid1_GridExporting(sender As Object, e As GridExportingArgs) Handles RadGrid1.GridExporting
02. 
03.    If isLoc <> True Then
04. 
05.        Dim ms As New MemoryStream(New UTF8Encoding().GetBytes(e.ExportOutput))
06. 
07.        Dim smtpClient As New SmtpClient()
08.        smtpClient.EnableSsl = True
09. 
10.        Dim mailMessage As New MailMessage()
11.        mailMessage.IsBodyHtml = True
12.        mailMessage.[To].Add(New MailAddress(Session("Email")))
13.        mailMessage.Subject = "Reporting service - Do Not reply"
14.        mailMessage.Body = "This report was sent from <br /><b>Reporting service</b> "
15.        mailMessage.Attachments.Add(New Attachment(ms, "Reporting service" & DocType))
16.        Try
17.            smtpClient.Send(mailMessage)
18.            'Label1.Text = "Message Sent" 
19.            MsgBox("Message Sent")
20.        Catch ex As Exception
21.            'Label1.Text = ex.ToString()
22.            MsgBox("Message not Sent")
23.        End Try
24.         
25.        Response.Redirect(Request.Url.ToString())
26.         
27.         
28. 
29.    End If
30.End Sub


The code in line 25 is not good for my project
because if I use the Response command it does a PostBack.
In my project the PostBack resets user configuration.
And if I delete the Response command, it sends an email and also creates a file in the user's computer.

I want only to send an email without PostBack and without creating a file in the user's computer.
How can I do that?

Thanks,
Daniel.



4 Answers, 1 is accepted

Sort by
0
Daniel
Top achievements
Rank 1
answered on 09 Apr 2014, 08:52 AM
Hi,

I had a mistake on the previous question.

The right question is:
My problem is that the Response command DOES NOT DO a PostBack and because of that,
when I call the Response command, it goes to:

If Not IsPostBack Then
' first initialization settings


 ,and resets user configuration.


I want only to send an email with PostBack and without creating a file in the user's computer.
How can I do that?

Thanks,
Daniel.
0
Daniel
Telerik team
answered on 10 Apr 2014, 12:24 PM
Hello Daniel,

A possible way around this issue would be to use a simple session flag which could help you avoid resetting the user configuration. Runnable demo below:

Public Property IsRefresh() As Boolean
    Get
        If Session("IsRefresh") Is Nothing Then
            Return False
        End If
        Return CBool(Session("IsRefresh"))
    End Get
    Set
        Session("IsRefresh") = value
    End Set
End Property
Protected Sub Page_Init(sender As Object, e As EventArgs)
    Button1.Click += Function(s, a)
    Response.Redirect(Request.Url.ToString())
 
End Function
    Button2.Click += Function(s, a)
    IsRefresh = True
    Response.Redirect(Request.Url.ToString())
 
End Function
 
    If Not IsPostBack AndAlso Not IsRefresh Then
        Response.Write("Resetting user settings...")
    Else
        Response.Write("User settings persisted")
    End If
 
    IsRefresh = False
End Sub

<asp:Button ID="Button1" runat="server" Text="Redirect" />
<asp:Button ID="Button2" runat="server" Text="Refresh" />

I hope this helps.

Regards,
Daniel
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Daniel
Top achievements
Rank 1
answered on 22 Apr 2014, 07:59 AM
Hi Daniel.

Indeed it has solved some of the problems,
But I have more problem:
When the user makes exporting,  all of the data in the grid disappear.
In my Website I have one page and the grids change only by functions (the page stay the same page). 
When I call RESPONSE command,  
the data on the grid disappears and the  data user reset.  
.
0
Daniel
Telerik team
answered on 22 Apr 2014, 10:56 AM
Hello Daniel,

I suppose the problem is in the way the RadGrid is bound. You can use that flag to determine whether you have to repopulate it with data or not.

Regards,
Daniel
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
Grid
Asked by
Daniel
Top achievements
Rank 1
Answers by
Daniel
Top achievements
Rank 1
Daniel
Telerik team
Share this question
or