Refer to:
Thanks master. it works. But if I using other function such as print to PDF or save data to excel, it can not return to main page, stay in loading page.
Coding of Print PDF
Protected Sub btn_Print_Click(sender As Object, e As EventArgs) Handles btn_Print.Click
System.Threading.Thread.Sleep(100)
Print()
End Sub
Protected Sub Print()
RateChart.Visible = True
BindRateChart()
Dim pdfDoc As Document = New Document(PageSize.A4.Rotate(), 10, 10, 10, 0)
Dim writer As PdfWriter = PdfWriter.GetInstance(pdfDoc, Response.OutputStream)
pdfDoc.Open()
Dim chFontPath As String = "c:\\windows\\fonts\\times.ttf"
Dim chBaseFont As BaseFont = BaseFont.CreateFont(chFontPath, BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED)
Dim chFont As iTextSharp.text.Font = New iTextSharp.text.Font(chBaseFont, 12)
Dim simplePhr1 As Phrase = New Phrase(Label37.Text)
Dim simplePhr4 As Phrase = New Phrase(Label38.Text)
Dim simplePara As Paragraph = New Paragraph()
simplePara.Add(simplePhr1)
simplePara.Add(Environment.NewLine)
simplePara.Add(simplePhr4)
simplePara.Add(Environment.NewLine)
Dim stream As MemoryStream = New MemoryStream()
RateChart.SaveImage(stream, ChartImageFormat.Png)
Dim chartImage As iTextSharp.text.Image = iTextSharp.text.Image.GetInstance(stream.GetBuffer())
chartImage.ScalePercent(75)
pdfDoc.Add(simplePara)
pdfDoc.Add(chartImage)
pdfDoc.Close()
Response.ContentType = "application/pdf"
Response.AddHeader("content-disposition", "attachment;filename=NQI_Chart_HAHO.pdf")
Response.Cache.SetCacheability(HttpCacheability.NoCache)
Response.Write(pdfDoc)
Response.End()
gvRate.Visible = False
System.Threading.Thread.Sleep(1000)
End Sub
Coding on Page_Load
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not IsPostBack Then
Dim script As String = "$(document).ready(function () { $('[id*=btn_Rate]').click(); });"
ClientScript.RegisterStartupScript(Me.GetType, "load", script, True)
End If
gvRate.DataBind()
btn_Print.Visible = False
btn_Download_RD.Visible = False
gvRate.Visible = False
Label39.Text = Label18.Text & Label19.Text
If String.IsNullOrEmpty(Label3.Text) Then
DropDownList2.Visible = False
DropDownList3.Visible = False
DropDownList4.Visible = False
DropDownList5.Visible = False
DropDownList2.SelectedIndex = -1
DropDownList3.SelectedIndex = -1
DropDownList4.SelectedIndex = -1
DropDownList5.SelectedIndex = -1
DropDownList6.SelectedIndex = -1
DropDownList7.SelectedIndex = -1
Label5.Text = String.Empty
Label6.Text = String.Empty
Label7.Text = String.Empty
Label8.Text = String.Empty
Label39.Text = String.Empty
Else
Label5.Visible = True
Label6.Visible = True
Label7.Visible = True
Label8.Visible = True
Label5.Text = "Start"
Label6.Text = "End"
Label7.Text = "Quarter/Year"
Label8.Text = "Quarter/Year"
DropDownList2.Visible = True
DropDownList3.Visible = True
DropDownList4.Visible = True
DropDownList5.Visible = True
End If
If String.IsNullOrEmpty(Label39.Text) Then
DropDownList6.Visible = False
DropDownList7.Visible = False
Label9.Text = String.Empty
Label10.Text = String.Empty
Label11.Text = String.Empty
Else
Label9.Visible = True
Label10.Visible = True
Label11.Visible = True
Label9.Text = "Hospital"
Label10.Text = "1st Hospital"
Label11.Text = "Compare with Other Hospital"
DropDownList6.Visible = True
DropDownList7.Visible = True
If Not IsPostBack Then
Dim script As String = "$(document).ready(function () { $('[id*=btn_Rate]').click(); });"
ClientScript.RegisterStartupScript(Me.GetType, "load", script, True)
End If
End If
GridView1.Visible = False
Try
Dim ScriptManager1 As ScriptManager = ScriptManager.GetCurrent(Me.Page)
Dim ScriptManager2 As ScriptManager = ScriptManager.GetCurrent(Me.Page)
ScriptManager1.RegisterPostBackControl(Me.btn_Download_RD)
Catch ex As Exception
End Try
End Sub
Html Coding
<%@ Page Title="About Us" Language="vb" MasterPageFile="~/Site.Master" AutoEventWireup="false"
CodeBehind="About.aspx.vb" Inherits="NQI_CHART.About" %>
<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.4.1/jquery.min.js"></script>
<script type="text/javascript">
function ShowProgress() {
setTimeout(function () {
var modal = $('<div />');
modal.addClass("modal");
$('body').append(modal);
var loading = $(".loading");
loading.show();
var top = Math.max($(window).height() / 2 - loading[0].offsetHeight / 2, 0);
var left = Math.max($(window).width() / 2 - loading[0].offsetWidth / 2, 0);
loading.css({ top: top, left: left });
}, 200);
}
$('form').live("submit", function () {
ShowProgress();
});
</script>
</asp:Content>
Coding of save data to excel
Protected Sub btn_Download_RD_Click(sender As Object, e As EventArgs) Handles btn_Download_RD.Click
System.Threading.Thread.Sleep(100)
Rate_RD()
End Sub
Protected Sub Rate_RD()
System.Threading.Thread.Sleep(100)
gvRate.Visible = True
Dim GridView1 As New GridView()
GridView1.AllowPaging = False
GridView1.AllowSorting = False
GridView1.Style.Clear()
GridView1.CellPadding = 0
GridView1.CellSpacing = 0
GridView1.GridLines = GridLines.None
GridView1.BorderStyle = BorderStyle.None
GridView1.BorderWidth = Unit.Pixel(0)
GridView1.AlternatingRowStyle.BorderStyle = BorderStyle.None
Dim DataTableRate As System.Data.DataTable = New System.Data.DataTable("DataTableRates")
For Each cell As TableCell In gvRate.HeaderRow.Cells
DataTableRate.Columns.Add(cell.Text.Trim())
Next
For Each row As GridViewRow In gvRate.Rows
DataTableRate.Rows.Add()
Dim k As Integer = 0
For k = 0 To row.Cells.Count - 1
DataTableRate.Rows(row.RowIndex)(k) = row.Cells(k).Text.Trim()
Next
Next
GridView1.DataSource = DataTableRate
GridView1.DataBind() ' Clear the response
Response.Clear()
' Set the type and filename
Response.AddHeader("content-disposition", "attachment;filename=NQI_HAHO_Data.xls")
Response.Charset = ""
Response.ContentType = "application/vnd.xls"
' Add the HTML from the GridView to a StringWriter so we can write it out later
Dim sw As New System.IO.StringWriter()
Dim hw As System.Web.UI.HtmlTextWriter = New HtmlTextWriter(sw)
GridView1.RenderControl(hw)
' Write out the data
Response.Write(sw.ToString())
Response.[End]()
End Sub