Problem with FileUpload control and doPostback

M

Marko Vuksanovic

I am trying to implement an upload progress indicator using atlas, using the following workaround:
http://forums.asp.net/thread/1321664.aspx

This is the code in FileUpload.apsx file is as follows:
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
<title> drag </title>
</head>
<body>
<form id="f1" enctype="multipart/form-data" runat="server">
<h4>Select a file to upload:</h4>
<atlas:ScriptManager ID="ScriptManager1" runat="server" EnablePartialRendering="true" />

<atlas:UpdatePanel ID="upResults" runat="server" Mode="conditional">
<Triggers>
<atlas:ControlEventTrigger ControlID="Upload" EventName="Click" />
</Triggers>
<ContentTemplate>
<asp:FileUpload id="FileUpload" runat="server"> </asp:FileUpload>
<asp:Button id="Upload" Text="Upload file" runat="server"> </asp:Button>
</ContentTemplate>
</atlas:UpdatePanel>

<asp:Button id="Button1" OnClick="UploadButton_Click" runat="server"></asp:Button>
<br /><br />
<atlas:UpdateProgress ID="uprProgress" runat="server">
<ProgressTemplate>
<img src="images/animated_loading.gif" /> Uploading....
</ProgressTemplate>
</atlas:UpdateProgress>

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

The relevant code from the code behind file is:

protected void Page_Load(object sender, EventArgs e)
{
Upload.Attributes.Add("onClick", "__doPostBack('" + Button1.ClientID + "','');return false;");
ClientScript.GetPostBackEventReference(Button1, "");
}

protected void UploadButton_Click(object sender, EventArgs e)
{
String savePath = @"C:\Temp\uploads\";
if (this.FileUpload.HasFile)
{
String fileName = FileUpload.FileName;
savePath += fileName;
FileUpload.SaveAs(savePath);
}
else
{
}
}

The problem is, in the line of code in the Page_Load Function, if I use the "onClick" the (ProgressTemplate is not displayed), if I use the "onClientClick" the ProgressTemplate is correctly displayed but the file is not uploaded.

Any help is greatly appreciated.

Many thanks,
Marko
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top