[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

ASP.net PostBackUrl

Posted on 2009-04-13
6
Medium Priority
?
824 Views
Last Modified: 2013-11-07
Hi,

I have a webpage (data.aspx) with a datagrid which paging and a button which can download that data to excel (excel.aspx).  When a user clicks on the button, an excel file downloads as it has a PostBackUrl attribute set to excel.aspx. This function works, OK.

However, after  I download the excel file, and click on a page on a page number on the datagrid, it download the excel file again. I suspect it is still posting back to excel.aspx when it should be returning to the same page (data.aspx).

Is there a way to change the PostBackUrl, download a file for example, and return the form so the original postbackurl file is retained?
0
Comment
Question by:klm555
  • 4
6 Comments
 
LVL 12

Expert Comment

by:Nirmalan Nagenthiran
ID: 24134649
0
 
LVL 1

Author Comment

by:klm555
ID: 24134914
Thanks, but I was looking on the lines of a function or command line to redirect back to the same page after the download.
0
 
LVL 1

Author Comment

by:klm555
ID: 24135136
Just for clarification, I am using "post" methods to filter the datagrid and excel file. i'm not considering using querystring at all.
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 14

Expert Comment

by:GiftsonDJohn
ID: 24136153
Please post the code for the button click event where you redirect to the Excel.aspx. Also the sample code of the Excel.aspx.vb
0
 
LVL 1

Author Comment

by:klm555
ID: 24143042
Attached is the code for the button. I trigger the postback by firing a btnExcel.click javascript command.
However, if I click the btnFilter after the file is downloaded the datagrid returns to normal functionality. It appears the postback page is set to "excel.aspx" until it is changed back again to "data,aspx" by pressing the second button/

The excel page, calls a component that converts a datagrid to an excel file.  It has one subroutine namely, Convert. This file is attached for convience also.

I have done some research and found a tutorial which is able to change the postback page dynamically by creating a custom button, albeit it is in C#, but I was able to converted it to VB, compiles with no errors, but I do not know how to call the new custom button to be included in the code.  If this tutorial is suitable with a few minor refinements, please let me know. http://weblogs.asp.net/stefansedich/archive/2008/01/16/crosspagepostback-in-new-window.aspx

Thanks points increased to 500
 
data.aspx
-----------------------------------------------------------------------
<asp:Button ID="btnExcel" runat="server"  PostBackUrl="excel.aspx" />
<asp:Button ID="btnFilter" runat="server" PostBackUrl="data.aspx" />
-----------------------------------------------------------------------
 
excel.aspx
-----------------------------------------------------------------------
mySQL = "SELECT * FROM Customer"
Dim myConnection As New Data.SqlClient.SqlConnection("db")
Dim myCommand As New Data.SqlClient.SqlCommand(mySQL, myConnection)
Dim myAdapter As New Data.SqlClient.SqlDataAdapter(myCommand)
Dim myDataSet As New Data.DataSet()
myAdapter.Fill(myDataSet)
myDataGrid.DataSource = myDataSet
myDataGrid.DataBind()
myDataGridToExcel.Convert(myDataGrid, Response)
----------------------------------------------------------------------
 
ExcelComponent.vb
----------------------------------------------------------------------
Public Shared Sub Convert(ByVal d As DataGrid, ByVal r As HttpResponse)
Response.Clear()
Response.ClearHeaders()
Response.Charset = ""
Response.Buffer = True
Response.ContentType = "application/ms-excel"
Response.AddHeader("Content-Disposition", "attachment;filename=Customer_List.xls")
Response.AddHeader("Content-Transfer-Encoding", "binary")
Dim myStringWriter As New System.IO.StringWriter()
Dim myHtmlwrite As New System.Web.UI.HtmlTextWriter(myStringWriter)
Dim myDataGrid As New DataGrid()
myDataGrid = d
myDataGrid.DataBind()
myDataGrid.RenderControl(myHtmlwrite)
r.Write(myStringWriter.ToString)
r.End()
End Sub
-----------------------------------------------------------------------

Open in new window

0
 
LVL 1

Accepted Solution

by:
klm555 earned 0 total points
ID: 24144263
Problem solved.
<asp:Button ID="btnExcel" runat="server" OnClientClick="setTimeout(function(){myform.action='data.aspx';}, 500);" PostBackUrl="excel.aspx" />

Open in new window

0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
With User Account Control (UAC) enabled in Windows 7, one needs to open an elevated Command Prompt in order to run scripts under administrative privileges. Although the elevated Command Prompt accomplishes the task, the question How to run as script…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Suggested Courses
Course of the Month17 days, 15 hours left to enroll

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question