AJAX

ASP.NET Download File to Web Browser

Many times you will want to allow a user to click on a link on your ASP.NET page and then cause a file to be downloaded to the user. This is common for operations like exporting a file as a CSV or PDF. But if the file to download is not in a publicly / web accessible location, then it is not as simple as just putting a hyperlink to the file. Also, if you want to add security to the access of the file (such as checking for a logged in user), you will want to protect these files and they will not be able to be hyperlinked directly in your page.

Ajax - Exception has been thrown by the target of an invocation

If you're working with Ajax in .NET, you'll probably see an exception like this at some point:

Exception has been thrown by the target of an invocation

Not very helpful.  What you need to do is tell the ScriptManager to catch post back errors and re-throw the InnerException.  Change your ScriptManager to look like this:

    <asp:ScriptManager ID="ScriptManager1" runat="server" OnAsyncPostBackError="ScriptManager1_AsyncPostBackError">
    </asp:ScriptManager>

Disable Button on Submit (Prevent multiple submits)

When a user clicks a button on a web page that submits the page (or does an AJAX asynchronous submit), depending on the load on the server and latency, the user may have to wait upwards of many seconds in order for the process to complete. During the time, a user may think something has not worked and may attempt to click the button again, even multiple times. If you are doing complex operations, it could cancel these actions and start over. Worse yet, if you are inserting items in a database, it could cause duplicate entries or other concurrency issues.

How to Install the ASP.NET AJAX Control Toolkit

There is no installer available for the Ajax Control Toolkit. You have to configure it manually. Here are the following steps to correctly install the toolkit.

- Unpack the AjaxControlToolkit-Framework3.5-NoSource.zip file to a local directory. You can download it here:

http://www.codeplex.com/Wiki/View.aspx?ProjectName=AjaxControlToolkit

- Create a "Microsoft ASP.NET" directory at the following path: