Ajax - How To Return An Error From A File Download Action Without Leaving The Current Page

Jul 12, 2010

I am calling a file download action from javascript:

$elem.click(function() {
window.location.href = 'MyController/MyFileDownloadAction';
});

The controller returns a file:

[code]...

This action has a pretty high likelyhood of throwing an exception (or at least not being able to return the file).

Due to the nature of the application (which contains a lot of dynamic content), I can't really redirect to an error page in this situation. The current page needs to stay open somehow.

So I'm ideally looking for something like a javascript pop-up, but afaik this isn't going to be possible since I don't know any way to return a javacript instruction in a non-ajaxed controller call. If I display an error page I need to force it to open in a new window some how. Is there any possible solution to this problem?

View 1 Replies


Similar Messages:

How To Launch The Download Of A File Without Leaving The Current Page

Mar 2, 2011

How can I force the download of a file on a ASP.NET page using datas from that page's ViewState?

Response.ClearContent();
Response.ContentType = "text/plain";
Response.AddHeader("Content-Disposition", "attachment; filename=" + "example.aaa");
Response.Write( this.ViewState["stuffs"] );
Response.End();

But if I do that the current page will be erased and return blank to the user.

Other examples says to create "download.aspx" and request it by javascript, but on a this new page I won't have access to the ViewState data of the first page.

The point is, how can I create a file, launch the download and don't lose the current page status?

View 2 Replies

Jquery - Return An Error In An Ajax Scenario From MVC Action?

May 14, 2010

I am using ASP.NET MVC with jquery. I have the following MVC Action that returns a partial page on Success. On Application Error, I am not sure what to send it for correctly handling it at the client side.

public ActionResult LoadFilterSet(int filterSetId)
{
try
{
BreadCrumbManager bcManager = this.ResetBreadCrumbManager(this.BreadCrumbManagerID);
GeneralHelper.LoadBreadCrumbManager(bcManager, filterSetId);
ViewData["BreadCrumbManager"] = bcManager;
return View("LoadFilterSet");
}
catch (Exception ex)
{
return Content("");
}
}

Following is my jquery ajax call. Notice that I am checking for the data length to make sure there are no errors. Please suggest me a better way of doing this.

$.ajax({
type: "GET",
dataType: "html",
async: true,
data: ({ filterSetId: selectedId }),
url: link,
contentType: "text/html; charset=utf-8",
success: function(data, textStatus) {
if (data.length > 0) {
// Clear the local filters first.
clearLocalFilters();
$('td.selected-filters table.filters-display').append(data);
}
}
});

View 2 Replies

AJAX :: Download LinkButton In UpdatePanel Throwing Error While File Download?

Jun 10, 2013

I have added linkbutton inside gridview to download, below is my code..

protected void lnkDownload_Click(object sender, EventArgs e)
{
try
{

[Code].....

its giving me following error

"Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack"

View 1 Replies

Jquery - Return Error From MVC Action?

Mar 4, 2010

I am using ASP.NET MVC for developing a web site. I am using jquery for AJAX functionality. In the action methods, I want to return some error to signal that the input is not correct or that the action could not be performed. In such error cases, I expect the jquery ajax error handler to be called and I can take appropriate action in there. I have not found a way how to do this. Following is my action method.In error cases, what should I be sending from an Action in order to get the jquery error handler triggered?

public ActionResult AddToFavourites(int entityId, string entityType)
{
if (!Request.IsAjaxRequest())

[code]...

View 2 Replies

Button That Performs A Server-side Action And Returns A File To Download?

Jul 28, 2010

I have an ASP.NET page (using ASP.NET AJAX and the Telerik RAD components) that provides a data table and an option to download data in CSV format.I have a requirement that a single button allow the user to download a data set. I have a system set up that's nearly working for me based off the solution in
http://stackoverflow.com/questions/104601/asp-net-response-redirect-to-new-window

<asp:Button ID="ExportCsvButton" runat="server" Text="Download to CSV/Excel"
byte[] csvBytes = someLongOperation();
Session[EXPORTED_SESSION_KEY] = csvBytes;
Response.Redirect("myexportpage.aspx", true);
protected void Page_Load(object sender, EventArgs e)
{
Response.Clear();
Response.ClearHeaders();
Response.ClearContent();
Response.AppendHeader("content-disposition", "attachment; filename=" + "file.csv");
Response.ContentType = "text/csv";
Response.AddHeader("Pragma", "public");
Response.BinaryWrite(Session[OtherPage.EXPORTED_SESSION_KEY] as byte[]);
Response.Flush();
Response.End();
}


This actually works quite well. When I click the 'Export to CSV' button, the page's UpdateProgress kicks in and my loading overlay appears (it's a CSS div that covers the window when visible). This can take some time depending on the data set (potentially several minutes), at which point I'm getting a window popup with my file.

View 1 Replies

C# - HttpContext.Current.Response Write File After Download Manager Starts?

Dec 17, 2010

I'm trying to create a ZIP file on the fly which might contain a few thousands of pictures.

[code]....

My question:

Is there a way to initiate the download (let the download manager on client side popup), and then start writing on the stream?

I monitored w3wp.exe (IIS) process, and it seems that the data is being written on memory instead of Stream.

When w3wp.exe memory usage riches a certain number, it releases the memory and nothing happens (no download).

View 2 Replies

HttpHandlers / Modules :: Redirect Shareware Download URL From A File To A Download Page?

Oct 13, 2010

I'm about to submit my pad file to multiple sharware sites but the pad file has to have a direct link to the download file and can't link to a download page which is what I would like to do, so I can track the traffic and get the downloader's email before allowing the download. I am running an ASP.NET site in VB. Is there a way to tell the web app to redirect to a specific aspx page when it receives a request for a specific file?

View 1 Replies

RenderAction Not Finding Action Method In Current Controller In Current Area?

Mar 15, 2010

I'm creating an ASP.NET MVC 2 (RTM) project that uses areas. The Index action of the Home controller of one area needs to use RenderAction to generate a sub-section of the page. The action called is also defined in the same Home controller. So the call should just be:

<% Html.RenderAction("List") %>

However, I get an exception:A public action method 'List' was not found on controller 'RareBridge.Web.Areas.Events.Controllers.HomeController'.

Note that I'm not in the "Events" area! I'm in a completely different area. If I remove the "Events" home controller, then the exception still occurs but names a different controller (still not the one I want it to call).

I've also tried providing the controller name and area to the RenderAction method, but the same exception occurs. What is going on here?

BTW: I am using Autofac as my IoC container

View 2 Replies

Redirect Current Page To Download Page?

Oct 21, 2010

I have problem when try auto download in another page that already been specify.In current page, I have button to trigger to redirect page to download page, but I wish to download done automatic, even it don't done automatic. It can be done using link to download file. File name wish to download, transfer using querystring, cookie, or session (I using cookie is this case).The redirect page and download from link button, work perfect just like I wish. But the problem is auto download dont' work properly.This what I already trying to do about problem auto download:

using if (!IsPostBack) condition. The download work, but the page don't redirect to download page and even that update progress keep running. (Actually i put update progress for purpose generate file before redirect and download).using timer. When is not postback condition, I trying enable the timer with interval 2sec.When in timer event is trigger i disable timer and trying download it. But the problem is timer dont disable, keep every 2 sec to download file.

View 1 Replies

Bad Request 400 Error - Leaving URL

Jan 4, 2011

Why leaving following URL leads to bad request error: [URL] It happens both - if I redirect to, say, ~default.aspx programatically (response.redirect("~Default.aspx"), and if I simply press to asp:hyperlink with URL="~Default.aspx" AND If I try to repeat this error on VS Dev.Server - it doesn't happen. If I try to repaet it by browsing IE on my server machine - it doesn't repeat! It happens only if I browse from dev. machine to uploaded website.

View 3 Replies

Creating Mobile Website Page To Download Symbian .sis File To Mobile Unable To Download Properly

Dec 10, 2010

i m creating asp.net Mobile website page to download symbian .sis file to mobile ,but its not geting download properly.its working perfectly on desktop.

View 2 Replies

Error In File After Download

Jul 17, 2010

I have word document which is opening perfectly at server but when i download it using button click event of my website it gets currept.i am using below code on button click to make document download. i am using .net framework 3.5

Response.Clear();
Response.AddHeader("Content-Disposition", "attachment; filename=StandardLetter" + _responseId.ToString() + ".doc");
Response.ContentType = "application/octet-stream";
Response.TransmitFile (Server.MapPath("~/document/letter/StandardLetter" + _responseId.ToString() + ".doc"));

View 3 Replies

Error Message Comes When Try To Download File?

Aug 31, 2010

On this page it generates a Excel sheet and allows user to download that. Even though there is a certificate error (trusting issue) it works fine with Firefox.(We can add the exception) But as shown below it does not work properly on IE (both 7 & 8) Is there any settings we can do on both client side or Server side. (I have turned off security for IE on server)

View 5 Replies

Web Forms :: File Download / Access Denied Error In IIS

Oct 1, 2012

I have an issue while downloading files from a folder.In my application,i have to upload files to a particular folder inside my solution. I dint face any issues while uploading the files to the folder. But while downloading the file from the folder i get an error Access to path 'C:FolderPath' is denied. I am using windows 7.

Below is the coding for download

protected void radgrdDocumnet_ItemCommand(object sender, GridCommandEventArgs e) {
if (e.Item is GridDataItem) {
GridDataItem item = e.Item as GridDataItem;
string id = userProcess.Encrypt(item.OwnerTableView.DataKeyValues[item.ItemIndex]["ID"].ToString());
if (e.CommandName == "download") {
System.IO.FileStream fs = null

[Code]....

View 1 Replies

State Management :: Set Value To Null Where User Is Leaving The Page?

Jan 10, 2011

I want to terminate an application stat or set value to null where user is leaving the page...

does anyone know how can I do that?

View 13 Replies

C# - Download A File Using AJAX?

Feb 5, 2011

hat's the best way to allow a user to pull down an RDP file, but to do so using AJAX? In other words, I have a hyperlink and I need an RDP file to be downloaded by the user, but without a full page refresh.

I tried to make an AJAX call using the following example for RDP. It seems to work on Chrome and Firefox, but not on any version of IE.

String content = <RDP Content Here>
Response.Clear();
Response.AddHeader("Content-Disposition", "attachment; filename=HelloWorld.rdp");
Response.Cache.SetCacheability(System.Web.HttpCacheability.NoCache);
Response.ContentType = "Content-Type=application/x-rdp rdp;charset=ISO-8859-1";
Response.AddHeader("Content-Length", content.Length.ToString());.......

View 1 Replies

Web Forms :: Warn User When Leaving A Page With Changed Data?

Jan 28, 2010

I'd like to know how I can warn a user when they're leaving a page where they've changed data (i.e. "You have unsaved data on this page, are you sure you want to abanon it?"). For example, the page has a few dropdown lists, some textboxes, etc. I'd like to warn them if they try to leave the page before saving the data. How can I do this? To add to my confusion, I also have a dropdown menu control (skmMenu) on the page that doesn't seem to have any events I can tie into.

View 9 Replies

State Management :: Session Variable Disappears When Leaving Page?

May 14, 2010

I have a session variable which contains a list of elements. The user defines filters, which are sent to the Database, which fills the object with the elements that match. Then, that list is shown in a table. The code goes something like this:

[Code]....

Inside that page there is a button, which sends the request given the user filters. The Server creates the object and the session variable is assigned a value.

[Code]....

It works when the user sets the filters. However, given that once done it, the session variable has a value, I don't understand why if you navigate to other pages, the table doesn't appear when you return, given that:

1. It works when you perform the query and reload the page

2. The Session variable should be set for the rest of the session

View 2 Replies

C# - How To Return Two Different Views From The Same Action In .NET MVC

Jan 13, 2011

I have two views which will both use the same Controller method:

//webServiceController.cs

//The actual method is about 40 lines of code. Truncated for readability.
public ActionResult Index()
{
object i = new List<WebServiceMethod>(); [code].....

The second view is a quick'n'dirty conversion to JSON so that I can do magical AJAX tricks with the data:

<%
// AjaxGetServiceData.aspx

// Convert web service response object into JSON for AJAX.
var jss = new System.Web.Script.Serialization.JavaScriptSerializer();
Response.Write(jss.Serialize(Model));

%>

I'd created a duplicate of the Index() method and called it AjaxGetServiceData(), but that defeats the purpose of MVC.

Resolution:I didn't ask my question very well, as evidenced by a 5-10 minute discussion I just had with a coworker about this very topic. He kept asking me the same question that many users on this page asked me: "How does the controller know which view to return?" I responded, "That's what I'm trying to figure out." I was trying to get the method to return a different view (or Json output) when AJAX was the requester. A string argument in the method was my solution.

This is what I ended up using to get my desired effect:

public ActionResult Index(string isJSON = "no")
{

/// ...All the code from before...[code]....

Then, when I want the JSON version, in my AJAX request I specify the URL as /MyController/Index/?isJSON=yes When I want my pretty table view, I just use /MyController/

View 2 Replies

MVC :: Get Current Controller And Action?

Mar 10, 2010

I have a user control in a modal popup for login form. It's ajax post so when login is successfull it doesn't update the rest of the page. Would like to just redirect the user to thier current page but not 100% on how to do this from the accountController.

View 4 Replies

Security :: Pages Won't Change From HTTPS To HTTP Once Leaving Secured Page?

Jul 16, 2010

I'm pretty new at configuring IIS and working with SSL. I've been having difficulty with switching from the HTTPs protocol to the HTTP protocol. I had set a small part of our website to the HTTPS protocol since it has an SSL certificate for online commmerce.

When users go through that part of the site the HTPPS protocol is set and runs fine, but when they try to leave by, say, clicking on a link to another part of the site (after they have visited the secured portion of the site) the HTTPS stays in the url. Is there something I'm doing wrong?

This is how the HTTPS is set on the site: this code is placed in an sslredirect.asp page located in a "SSL" folder:

<%
Response.Buffer = True
If (Request.ServerVariables("HTTPS") = "off") Then
sQ = Request.ServerVariables("QUERY_STRING")
sURL = "https" & Right(sQ, (Len(sQ)-8))
sURL = Replace(sURL, ":80", "")
Response.redirect(sURL)
End if
%>

View 1 Replies

Download The Pdf File From Page?

Sep 14, 2010

how to download the .pdf file from the .aspx page

View 5 Replies

File Download Page

Dec 21, 2011

I am writing something that will use my database to generate/populate some Word/Excel Template Documents for Contracts. These will be written to a directory on my server that I want my user to be able to have access to to download these contracts from. I was thinking a GridView with a TemplateField with a Hyperlink in it for simplicity's sake.

View 3 Replies

AJAX :: Download File When Use CalendarExtender?

Dec 24, 2010

I m facing one problem whenover I use ajax calendar i m using this code at the time of file download

TargetControlID="TextBox1" & TargetControlID="TextBox2" is associated from ajax CalendarExtender
string abc = "CPCB_" + TextBox1.Text + "_" + TextBox2.Text;
Current.Response.Buffer = true;

[code]...

View 1 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved