AJAX AjaxFileUpload UploadComplete Event Confusion

David Bach
David Bach used Ask the Experts™
on
Greetings:

I am quite confused as to what I can do and what I cannot do within the UploadComplete event of the AjaxFileUpload control.

There are 2 ASPX Label controls which are assigned values within the UploadComplete event, however, the assigned values do not appear on the page after the event completes. The uploaded file is saved to the designated directory, however.

I'm including the ASPX, the VB code behind and the web.config files as follows:

ASPX
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
	<title></title>
</head>
<body>
	<form id="form1" runat="server">
		<div>

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

			<asp:Label ID="Label1" runat="server"></asp:Label>

			<ajaxToolkit:AjaxFileUpload ID="AjaxFileUpload1" runat="server" AllowedFileTypes="jpeg,jpg,gif" />

			<asp:Label ID="Label2" runat="server"></asp:Label>

		</div>
	</form>
</body>
</html>

Open in new window

VB Code Behind
Imports AjaxControlToolkit

Partial Class _Default
	Inherits System.Web.UI.Page

	Private Sub AjaxFileUpload1_UploadComplete(sender As Object, e As AjaxFileUploadEventArgs) Handles AjaxFileUpload1.UploadComplete

		Label1.Text = "Here we are 1."

		AjaxFileUpload1.SaveAs("C:\inetpub\ClientWebs\AjaxFileUploadSync\Images\" & e.FileName)

		Label2.Text = "Here we are 2."

	End Sub

End Class

Open in new window

web.config
<?xml version="1.0" encoding="utf-8"?>

<configuration>

	<system.web>
		<compilation debug="true" targetFramework="4.0" />
	<pages>
      <controls>
        <add tagPrefix="ajaxToolkit" assembly="AjaxControlToolkit" namespace="AjaxControlToolkit" />
      </controls>
    </pages></system.web>

	<system.webServer>

		<handlers>

			<add name="AjaxFileUploadHandler" verb="*" path="AjaxFileUploadHandler.axd" type="AjaxControlToolkit.AjaxFileUploadHandler, AjaxControlToolkit" />

		</handlers>

	</system.webServer>
</configuration>

Open in new window

Any assistance you might provide would be most helpful.


Much thanks,
David Bach
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Chinmay PatelChief Technology Ninja
Distinguished Expert 2018

Commented:
Hi David,

I don't see Masterpage OR UpdatePanel. Without that AJAX won't work in ASP.Net WebForms.
https://docs.microsoft.com/en-us/dotnet/api/system.web.ui.updatepanel?view=netframework-4.8

Regards,
Chinmay.
David BachPartner

Author

Commented:
Greetings Chinmay:

I changed my files as follows:

ASPX
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
	<title></title>
</head>
<body>
	<form id="form1" runat="server">
		<div>

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

			<asp:UpdatePanel ID="UpdatePanel1" runat="server">

				<ContentTemplate>

					<asp:Label ID="Label1" runat="server"></asp:Label>

					<ajaxToolkit:AjaxFileUpload ID="AjaxFileUpload1" runat="server" AllowedFileTypes="jpeg,jpg,gif" />

					<asp:Label ID="Label2" runat="server"></asp:Label>

				</ContentTemplate>

			</asp:UpdatePanel>

		</div>
	</form>
</body>
</html>

Open in new window

VB Code Behind
Imports AjaxControlToolkit

Partial Class _Default
	Inherits System.Web.UI.Page

	Private Sub AjaxFileUpload1_UploadComplete(sender As Object, e As AjaxFileUploadEventArgs) Handles AjaxFileUpload1.UploadComplete

		Label1.Text = "Here we are 1."

		AjaxFileUpload1.SaveAs("C:\inetpub\ClientWebs\AjaxFileUploadSync\Images\" & e.FileName)

		Label2.Text = "Here we are 2."

		UpdatePanel1.Update()

	End Sub

End Class

Open in new window

This is syntactically correct, however, the AjaxFileUpload event ends with an error, and the Label controls are not rendered.

If I may ask, how would you change what I have in order for the ASPX Label controls to be visible after the upload event please?

Where might I have missed documentation indicating an ASP.NET UpdatePanel control is required for AJAX events such as file uploading?


Much thanks, Chinmay ...
David Bach
Chinmay PatelChief Technology Ninja
Distinguished Expert 2018

Commented:
Hi David,

Please let me know which error you get? it is difficult and to guess what error you ran into.

Answers is bit long and WebForms are really really not recommended nowadays so I will keep it short. Basically, they are not required for AJAXupload (or for that matter any action), but UpdatePanel is needed if you want to change page's content without a round trip (Postback) to the server. Please read this article: https://docs.microsoft.com/en-us/previous-versions/bb399001(v=vs.140) for details.

Let me know the error that you are getting and I will see what can be done.

PS: I am between some critical deliveries and might take some time to revert, please refer to the article above and see if you missed something.

Regards,
Chinmay.
C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

David BachPartner

Author

Commented:
Greetings Chinmay:

If Web Forms are not recommended are folks using MVC?


Much thanks, Chinmay ...
David Bach
Chief Technology Ninja
Distinguished Expert 2018
Commented:
Hi David,

Really sorry for missing your response. Yes. MVC is the way out and if you ask me, you have to check out ASP.Net Core. I was used to be a WebForm guy... not anymore. I prefer ASP.Net Core over everything else.

Regards,
Chinmay.
David BachPartner

Author

Commented:
Greetings Chinmay:

Thank you for your response. Having been in IT for 47 years I need to seriously think about learning a new model for websites and all this entails.

I feel there are folks still working with the older model of building websites with web.config, forms and the like. Unless the AJAX folks are saying their routines will not fully work unless one learns and uses ASP.NET Core with MVC, I will change how documents are uploaded for my clients.

Chinmay, I appreciate your responses to this thread.


Much thanks, Chinmay,
David Bach
Chinmay PatelChief Technology Ninja
Distinguished Expert 2018

Commented:
Hi David,

I am not saying that it won't work. It is just that the WebForms were fundamentally flawed but they were required to migrate large number of VB6 / WinForm developers to something familiar. Your current solution will continue working for foreseeable future BUT sooner or later, you will have to jump ship.

In the mean time, let me know if there are any hurdles. I am more than happy to help.

Regards,
Chinmay.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial