I have a home/main menu page. There's a link to the form. If you run the form with inputs, you get Excel output. If you click 'open' to open that output in the browser, the back-button takes you to the home/main menu.
Which is understandable, since if the form page is X.aspx, the binaryWrite that outputs the Excel doesn't really change that.
The problem is that if there's a postback, the back button takes you to the form page. This is inconsistent. If I run the page or a drop down causes a postback, I really want the back-button to take me to the form field, so that I can run the excel sheet again.
Things I've tried.
I tried adding a location header.
e.ContentFileName = "ELTFile.Output.xls";
Before the response.Writing ...
private void SendFileToBrowser(DownloadFileEventArgs e)
{
if (!e.Cancel && e.FileObject != null)
{
this.Page.Response.Clear();
this.Page.Response.ClearContent();
this.Page.Response.AddHeader("Content-Disposition", string.Format("inline; filename={0}", e.ContentFileName));
this.Page.Response.AddHeader("Content-Length", e.FileObject.LongLength.ToString());
this.Page.Response.AddHeader("Location", e.ContentFileName);
this.Page.Response.ContentType = e.ContentType;
this.Page.Response.BinaryWrite(e.FileObject);
this.Page.Response.End();
}
}
And I tried
Response.Cache.SetCacheability(HttpCacheability.Public);
As well as
Response.Cache.SetCacheability(HttpCacheability.Server);
But basically, depending on whether or not I post back before I click the 'Submit' button to generate the Excel, I get the main menu (don't want) or the form page (want). I want the form page every time. Basically I want to tell the browser "I know it's not really a different page, but treat it that way, will ya please?"
You cannot directly add pages to a browser history.
You could make your application such that the form is always a page ahead of the excel output.
To do this, have a separate page to output the excel.
When you have the inputs to generate the excel, Response.Redirect to the generation page.
This will keep your input form in the browser history.
Note: you could redirect to the same page too if you liked, but that would need you to track it.
Related
i have two asp page,first one is home and second one is test. In home page user can select the type of test they want to take up, and after pressing start button a new window is open for taking the test. What i want to achieve is , after completing the test i want to close the test window and redirect to another page, and this redirect should hit the previously opened home window.
You don't clarify that you have popup window or blank window i am aspecting for the popup
In submit click button press
String x = "<script type='text/javascript'>window.opener.location.href='**Your new url of new page after completing test**';self.close();</script>";
ScriptManager.RegisterClientScriptBlock(this.Page,this.Page.GetType(), "script", x,false);
From self close you will be able to close current window and by window.opener.location.href you will able to redirect to new url
I hope this will help you
regards....:)
Yes you can do these 2 ways:
Window.Open() /.showmodalDialog() and keep parent and child open as well, or
On the home page click on your start button. Use code Response.Redirect("~/Test.aspx"); assuming it resides with Home.aspx. Take your test using ASp.Net wizard control or hiddens divs what ever suits you easy. Manipulate data on test page , save and get result to and from database using SqlConnection and SqlCommand assuming you have Sql Server as backend. Hold the table or any value in either cache or Session and throw it on your home page. Do whatever you want.
This will be not possible. What you can do is to redirect the user to the home page after completing the test, but this will be in the same windows.
I am trying to make a button that when clicked call a procedure but also opens in a pop-up. I can't find how to do it because all the search i did only tells me to put it on te clientclick :
<asp:Button ID="cmbGen" runat="server" Width="240px" Text="Générer le rapport" OnClick="cmbGen_Click"></asp:Button>
the onclick opens up a pdf, and its not working well on Ie, so, to solve this i would like the pdf to opens in a pop up
not sure what i could do.. anyone got an idea ?
EDIT
The code is pretty big, but basicaly, depending on what checkboxed were checked, it will create a pdf file and show it. this works pretty well, but it opens up in the current page, i would like to make it in a pop-up
A Button always submits a postback to the server on the current window, so you can't directly tie a new window to it. You'll need to write some javascript to do that, and open a popup window.
You can do this lots of ways - you can hook up an event handler to the button so when it's clicked, it immediately opens a new window, and that window is pointed to your server code which returns the PDF. Or you can do a regular postback, and return some javascript that pops up a new window. But either way, javascript is the only way to get a popup from a form button.
Liam's suggestion of making a link instead of a button is probably the simplest method - you can throw an image on that link to make it look like a button if you want.
EDIT
Based on your comment on the other answer, your simplest bet would be to return some javascript on the button click method, using ClientScript.RegisterStartupScript or whatever Microsoft is recommending these days. You can do whatever logic you need to first, then get that into a new handler either through session or querystring parameters, and have the client pop up a new window pointing to that handler.
Can't see you c# so it's not 100% sure what you want but why use a asp:Button at all:
Générer le rapport
Got a strange one, here.
I'm working on a basic ASP.NET/C# code-behind app where summary data is listed in a grid, and each record has an accompanying "update" button. Clicking the button triggers a window.open() where the ID for each row of the grid is passed into a query string to retrieve the related record for edit in the new window.
Example from the rendered "grid" page:
window.open('EditTool.aspx?ID=' + ID, 'new_window', width=550, height=300');
When the page opens from the button, it can take upwards of 10 seconds to render. When I open a new tab and just paste the URL and query string content into the address bar, the page renders almost immediately.
I've peppered the content of the page with log4net statements, and it looks like all of the controls and code-behind C# executes in a few milliseconds.
For investigation's sake, I've got popup blockers deactivated, and I've tried this on IE7 (workplace standard, ugh), FF, and Chrome.
Any ideas as to how to make the rendering faster, or where else I can look to see what's slowing it down?
Update:
I've created a new shell webapp that has a button opening an empty (just the stuff that gets added when you "Add New Item") ASPX as a popup. The popup renders immediately. I've also modified my existing app to open an empty popup, and I get the same delay. It's looking like the app server is waiting to process something before it starts processing the page, rather than rendering the page, slowly.
Does ASP.NET have a setting where you can tell it not to recompile a page on each render?
I'm serving up PDFs from a SQL db and presenting them in the browser. I'm trying to figure out a way to embed a number in the PDF dynamically so that the recordID for that PDFs SQL record is available to me when the user submits the XML form data. The user hits the submit button on the form and the form submits its XML data to my submission page. If there is some way of changing the submission URL on the fly then I could do a query string to pass my self the recordID. I'm not generating the PDF in code, its being created by hand and then uploaded to my site.
Edit
User is given a link someServer.com/pdfLink.aspx?formID=5 they go there and that pages pulls a PDF from the DB and displays it. This pulls up acrobat in browser full size so my aspx page isn't in control of submitting the completed form, Acrobat is. The user fills out the form and hits the submit button in the form. This submit button was set up at form design time to point to another page someSite.com/pdfSubmit.aspx The submit button posts the XML data to that page and I can process it. I need the recordID in the query string for the someSite.com/pdfSubmit.aspx page. To do this I would need to modify the PDF to either add the recordID and query string to the submit button's submit URL, or embed it in the PDF else ware. The big question is how do I modify the PDF just before I display it via someServer.com/pdfLink.aspx?formID=5 to do either of these two options.
Embedding a number in PDF is not exactly kosher, but there are some things that you can do that will honor the spec.
The current PDF spec says that "The last line of the file shall contain only the end-of-file marker
%%EOF
but there is some wiggle room - the implementation details say that it doesn't technically have to be the last line of the file, but only has to appear in the last 1K and, generally speaking, if you don't muck with things too much, most compliant readers won't even blink. If I had to do this, I would be inclined to add a newline (if there isn't one), then a % (which is a PDF comment), a marker to let me know it's mine, and finally the number. So something like:
// assume we already know it ends with %%EOF
void AppendNumberToPdf(Stream stm, int number, bool addNewline)
{
stm.Seek(0, SeekOrigin.End); // go to EOF
StreamWriter writer = new StreamWriter(stm, new ASCIIEncoding(), 1024);
writer.WriteLine(string.Format("{0}% {1} {2}", (addNewLine ? "\n" : ""), kMyMarkerString, number));
writer.Flush();
}
kMyMarkerString should be something like "MyApplicationDocumentIdentifier:" or some such thing that will make it easy to identify your tracks.
The querystring is read-only so you cannot dynamically change it at runtime. However can you:
Add the recordID to the form at the time the submit page is initially rendered
Can you process the submit form and then do a Response.Redirect or Server.Transfer to the correct page with the recordid parameter added to the querystring
While trying #plinth's suggestion I realized I had to change from XML submission (since his data was on the PDF directly. So I changed the form to submit as XDP which has XML data + embedded PDF. When I did this and viewed the raw XDP that the form submitted I ran across this.
<?xml version="1.0" encoding="UTF-8" ?>
<?xfa generator="XFA2_4" APIVersion="3.0.8262.0"?>
<xdp:xdp xmlns:xdp="http://ns.adobe.com/xdp/" timeStamp="2010-05-04T15:15:00Z" uuid="6d0944c8-1573-442c-9c85-11e372bd38c3">
<xfa:datasets xmlns:xfa="http://www.xfa.org/schema/xfa-data/1.0/">
<xfa:data>
<form1>
<TextField1>TestMe</TextField1>
</form1>
</xfa:data>
</xfa:datasets>
<pdf href="ViewPDF.aspx?formID=10" xmlns="http://ns.adobe.com/xdp/pdf/" />
</xdp:xdp>
Notice the 2nd to last line. It automatically includes the PDF's url which had the formID value that I needed. So all I had to do was get the XDP instead of pure XML post from the form and it gives me everything I needed.
I am using jQuery to simulate a popup, where the user will select a series of filters, which I hope to use to rebind a ListView in the original window.
The "popup" is opened via an ajax request and the content is actually a diferent aspx file (the rendered output is injected into a div that acts as the popup).
I have another ListView in this popup, and it has pagination.
My problem is that since the popup is in reality html content inside a div in the same page, when I try to paginate, the whole page postbacks and is replaced with the aspx that has the filters.
How can I fix this?
I tried using an update panel to contain the ListView but it didn't work.
$("div.yourthingie").hide();
Will hide the part you want to show :) Instead of generating the popup on the fly, leave a small part already made, and hide it in the begining, when you need to show, unhide and add the information you need to.
Hope it helps
Either get rid of the HTML "crust" and just produce the <div> with its contents, or use an IFRAME.
First, let's think through what is happening. When you submit the original page, you are taking a "normal" Request/Response trip to get the code. On the page is a JQuery AJAX bit that fires off what is essentially a modal dialog. The desired effect is the user plays with the new page until they have figured out their filters and submits back. The problem is this "modal page" loses information when someone paginates.
The solution to this is fairly simple, in theory. You have to store the "filters" in the popped up page so they can be resent, along with pagination information. OR you have to cache the result set while the user paginates.
What I would do to solve this is create a static page that has the "filters" in place and work out the AJAX kinks separate from having the page post back to a parent page. Once you have all of the AJAX bits working properly, I would then link it into the popup routine and make sure the pagination is still non-problematic. THe final problem is creating a JavaScript routine that sends back to the parent page and allows the parent page to send its JQuery bits back to the server.
I am not sure about the HTML DIV part of the equation and I think you can solve the problem without this solution. In fact, I believe you can make the "modal popup" page without invoking AJAX, if it is possible to either a) submit the filters to apply via the querystring or b) fake a form submit to the second page. The query string is an easier option, but it exposes some info. Faking a form submit is not that difficult, overall, but could be problematic with a popup.
I am just firing off some ideas, but I hope it spurs something for you.