if you look around the forums and google, you can read more about the problem if your interested, but the code project solution should get you started.
Jonathan Minond
http://www.Jonavi.com
http://www.jonavi.com/Default.aspx?pageID=21
http://RainbowBeta.com
http://community.rainbowportal.net/blogs/jonathans_rainbow_blog/default.aspx
http://dotnetslackers.com/community/blogs/jminond/default.aspx
Controls that are incompatible with partial-page rendering can still be used on a page outside
UpdatePanel controls. Additionally, in some cases you can use the controls in a specific way to make them compatible with partial-page updates. For example, you can use the
Login,
ChangePassword, or PasswordRecovery controls inside an
UpdatePanel control if you can convert their contents to templates. (If you are using Visual Studio, in Design view you can convert the controls by using smart-tag menu commands such
as Convert to Template or Customize Create User Step.) When you convert these controls into editable templates, the validation controls that are used in the control are defined declaratively by using markup in
the page. To make the validators compatible with an
UpdatePanel control, set the
EnableClientScript property of the validators to false. This disables the client script that would ordinarily be used to perform validation in the browser. As a result, during an asynchronous postback, the validators perform
validation on the server. However, because only the content of the
UpdatePanel is refreshed, the validators can provide the kind of immediate feedback that is ordinarily provided by client script.
To use a FileUpload control inside an
UpdatePanel control, set the postback control that submits the file to be a
PostBackTrigger control for the panel.
All other controls work inside
UpdatePanel controls. However, in some circumstances, a control might not work as expected inside an
UpdatePanel control. These circumstances include the following:
Registering script by calling registration methods of the
ClientScriptManager control.
Rendering script or markup directly during control rendering, such as by calling the
Write(String) method.
If the control calls script registration methods of the
ClientScriptManager control, you could use corresponding script registration methods of the
ScriptManager control instead. In that case, the control can work inside an
UpdatePanel control.
Jonathan Minond
http://www.Jonavi.com
http://www.jonavi.com/Default.aspx?pageID=21
http://RainbowBeta.com
http://community.rainbowportal.net/blogs/jonathans_rainbow_blog/default.aspx
http://dotnetslackers.com/community/blogs/jminond/default.aspx
I am having the same problem but it seems that it should work as I don't have a FileUpload control inside the Update Panel, I'm just trying to update a label when the Upload button is clicked. I guess it has to do with since the button_click is getting info
from the FileUpload control, it is unable to do so, is this correct?
From what you are saying you have part of a page relying on a full postback, and part on partial updates.
When the submit is clicked for the upload, and the page posts back, you will need to use code behind to set the label inside the update panel, using something like
If you do not set the label on the postback, it will never get the value, as the update panel wont know what you want from it. The update panel is a graet control, but it can't jsut automate everything.
So, since your uplaod control is outside the panel, the panel is not even aware of the upload control, file, or any of that.
Jonathan Minond
http://www.Jonavi.com
http://www.jonavi.com/Default.aspx?pageID=21
http://RainbowBeta.com
http://community.rainbowportal.net/blogs/jonathans_rainbow_blog/default.aspx
http://dotnetslackers.com/community/blogs/jminond/default.aspx
Yeah, I'm setting the text of the label in the code behind. Here is more of what I'm doing.
When the user selects a file to upload from the browse button, they will hit the Upload button(Actually named submit) to check to see if the file passes certain criteria. If it does, then it will store it to be saved later when a final button is clicked
to submit form. What is actually messing up is on Button_Click I have an if statement to see if the fileupload has a file, like so:
if (FileUpload1.HasFile)
{
//Do Stuff
}
Well it is skipping right over this and going to the else statement. The only thing in my update panel is my label. Any ideas? I can post my full code if needed, thanks!!
So what I am trying to do is, have a user select a file to upload. Since I am only going to accept images, I will test the extension. I also want to limit the file size to under 2mb, so I will test that(haven't implemented in code yet). If the file they
have selected passes, then I want the label to say "File Accepted", and store the file upload information for a later button click. This will happen once the user has finished filling out the rest of the form. Eventually, I will put an UpdateProgress control
on the page while it is checking if the file is allowed. I would rather not have it post back for this, so if I can get it to work, that would be great. BTW, this will all work fine if I take the label out of the update panel.
What happens when I run this, is it will go to the else statement of the first if and return "Please select a file." Meaning that FileUpload1.HasFile is returning false. The only reason I can see that this is happening is because the UpdatePanel can not
access that info from the FileUpload control?
kaushalparik27
All-Star
26096 Points
3622 Posts
MVP
File Upload Control is not working in Update Panel
May 01, 2007 03:49 AM|LINK
hi friend...
i am using update panel... in one of my aspx page (ASP.NET 2.0)
there is a file upload control in update panel which is used to upload company logo on server..
when i remove the update panel.. than file upload is working properly..
but when i again place an update panel then file upload control is not working and its giving me error.. in like
If String.IsNullOrEmpty(fldLogo.PostedFile.FileName.ToString) Then
as object reference not set to an instance of an object...
can any body help me ?
any idea ??
[KaushaL] || BloG || Twitter
jminond
Contributor
2898 Points
608 Posts
Re: File Upload Control is not working in Update Panel
May 01, 2007 03:59 AM|LINK
This problem is somewhat well documented, the update panel is listed as not working with certain controls.
File upload, and tree view being 2 of the biggies.
IN any case, one solution is available on code project:
http://www.codeproject.com/useritems/simpleajaxupload.asp
if you look around the forums and google, you can read more about the problem if your interested, but the code project solution should get you started.
http://www.Jonavi.com
http://www.jonavi.com/Default.aspx?pageID=21
http://RainbowBeta.com
http://community.rainbowportal.net/blogs/jonathans_rainbow_blog/default.aspx
http://dotnetslackers.com/community/blogs/jminond/default.aspx
kaushalparik27
All-Star
26096 Points
3622 Posts
MVP
Re: File Upload Control is not working in Update Panel
May 01, 2007 04:26 AM|LINK
i dont know about this thing..
well i set trigger to the button i want to do asynchronous postback...
and its working... with full postback to fileupload control (upload button click)
and u provide me some link for the document you have specified inyour post .. which controls don't work with update panel ??
thanks
[KaushaL] || BloG || Twitter
jminond
Contributor
2898 Points
608 Posts
Re: File Upload Control is not working in Update Panel
May 01, 2007 12:37 PM|LINK
From the online documentation:
http://ajax.asp.net/docs/overview/UpdatePanelOverview.aspx
Controls that Are Not Compatible with UpdatePanel Controls
The following ASP.NET controls are not compatible with partial-page updates, and are therefore not supported inside an UpdatePanel control:
TreeView and Menu controls.
Web Parts controls. For more information, see ASP.NET Web Parts Controls.
FileUpload controls when they are used to upload files as part of an asynchronous postback.
GridView and DetailsView controls when their EnableSortingAndPagingCallbacks property is set to true. The default is false.
Login, PasswordRecovery, ChangePassword, and CreateUserWizard controls whose contents have not been converted to editable templates.
The Substitution control.
Validation controls, which includes the BaseCompareValidator, BaseValidator, CompareValidator, CustomValidator, RangeValidator, RegularExpressionValidator, RequiredFieldValidator, and ValidationSummary control.
Controls that are incompatible with partial-page rendering can still be used on a page outside UpdatePanel controls. Additionally, in some cases you can use the controls in a specific way to make them compatible with partial-page updates. For example, you can use the Login, ChangePassword, or PasswordRecovery controls inside an UpdatePanel control if you can convert their contents to templates. (If you are using Visual Studio, in Design view you can convert the controls by using smart-tag menu commands such as Convert to Template or Customize Create User Step.) When you convert these controls into editable templates, the validation controls that are used in the control are defined declaratively by using markup in the page. To make the validators compatible with an UpdatePanel control, set the EnableClientScript property of the validators to false. This disables the client script that would ordinarily be used to perform validation in the browser. As a result, during an asynchronous postback, the validators perform validation on the server. However, because only the content of the UpdatePanel is refreshed, the validators can provide the kind of immediate feedback that is ordinarily provided by client script.
To use a FileUpload control inside an UpdatePanel control, set the postback control that submits the file to be a PostBackTrigger control for the panel.
All other controls work inside UpdatePanel controls. However, in some circumstances, a control might not work as expected inside an UpdatePanel control. These circumstances include the following:
Registering script by calling registration methods of the ClientScriptManager control.
Rendering script or markup directly during control rendering, such as by calling the Write(String) method.
If the control calls script registration methods of the ClientScriptManager control, you could use corresponding script registration methods of the ScriptManager control instead. In that case, the control can work inside an UpdatePanel control.
http://www.Jonavi.com
http://www.jonavi.com/Default.aspx?pageID=21
http://RainbowBeta.com
http://community.rainbowportal.net/blogs/jonathans_rainbow_blog/default.aspx
http://dotnetslackers.com/community/blogs/jminond/default.aspx
hooked82
Member
20 Points
12 Posts
Re: File Upload Control is not working in Update Panel
May 01, 2007 04:26 PM|LINK
jminond
Contributor
2898 Points
608 Posts
Re: File Upload Control is not working in Update Panel
May 01, 2007 04:49 PM|LINK
From what you are saying you have part of a page relying on a full postback, and part on partial updates.
When the submit is clicked for the upload, and the page posts back, you will need to use code behind to set the label inside the update panel, using something like
if(IsPostBack) {
.....
// Handle Upload File Code
....
txtLabelContro.Text = "Whatever string you want";
}
If you do not set the label on the postback, it will never get the value, as the update panel wont know what you want from it. The update panel is a graet control, but it can't jsut automate everything.
So, since your uplaod control is outside the panel, the panel is not even aware of the upload control, file, or any of that.
http://www.Jonavi.com
http://www.jonavi.com/Default.aspx?pageID=21
http://RainbowBeta.com
http://community.rainbowportal.net/blogs/jonathans_rainbow_blog/default.aspx
http://dotnetslackers.com/community/blogs/jminond/default.aspx
hooked82
Member
20 Points
12 Posts
Re: File Upload Control is not working in Update Panel
May 01, 2007 09:53 PM|LINK
Yeah, I'm setting the text of the label in the code behind. Here is more of what I'm doing.
When the user selects a file to upload from the browse button, they will hit the Upload button(Actually named submit) to check to see if the file passes certain criteria. If it does, then it will store it to be saved later when a final button is clicked to submit form. What is actually messing up is on Button_Click I have an if statement to see if the fileupload has a file, like so:
if (FileUpload1.HasFile)
{
//Do Stuff
}
Well it is skipping right over this and going to the else statement. The only thing in my update panel is my label. Any ideas? I can post my full code if needed, thanks!!
chetan.sarode
All-Star
53389 Points
9034 Posts
Re: File Upload Control is not working in Update Panel
May 02, 2007 05:43 AM|LINK
FileUpload controls when they are used to upload files as part of an asynchronous postback.
Senior Software Engineer,
Approva Systems Pvt Ltd, Pune, India.
jminond
Contributor
2898 Points
608 Posts
Re: File Upload Control is not working in Update Panel
May 02, 2007 12:33 PM|LINK
If the label is the only thing in the update panel, what do you need it for?
The upload button will cause the post back for you anyway, unless you follow one of the other methods mentioned.
So if you have the postback, and are setting the label then, remove the update panel, and use standard IsPostBack logic.
Can you post your whole ASPX and CodeBehind Pages? So we can see what is going on?
http://www.Jonavi.com
http://www.jonavi.com/Default.aspx?pageID=21
http://RainbowBeta.com
http://community.rainbowportal.net/blogs/jonathans_rainbow_blog/default.aspx
http://dotnetslackers.com/community/blogs/jminond/default.aspx
hooked82
Member
20 Points
12 Posts
Re: File Upload Control is not working in Update Panel
May 02, 2007 06:46 PM|LINK
So what I am trying to do is, have a user select a file to upload. Since I am only going to accept images, I will test the extension. I also want to limit the file size to under 2mb, so I will test that(haven't implemented in code yet). If the file they have selected passes, then I want the label to say "File Accepted", and store the file upload information for a later button click. This will happen once the user has finished filling out the rest of the form. Eventually, I will put an UpdateProgress control on the page while it is checking if the file is allowed. I would rather not have it post back for this, so if I can get it to work, that would be great. BTW, this will all work fine if I take the label out of the update panel.
What happens when I run this, is it will go to the else statement of the first if and return "Please select a file." Meaning that FileUpload1.HasFile is returning false. The only reason I can see that this is happening is because the UpdatePanel can not access that info from the FileUpload control?
Code Behind:
Label SubmitButtonLabel2= (Label)UpdatePanel1.FindControl("SubmitButtonLabel");
if (FileUpload1.HasFile)
{
string[] fileName = FileUpload1.FileName.Split('.');
if ((fileName[fileName.Length - 1] == "jpg") ||
(fileName[fileName.Length - 1] == "gif") ||
(fileName[fileName.Length - 1] == "bmp") ||
(fileName[fileName.Length - 1] == "jpeg") ||
(fileName[fileName.Length - 1] == "png"))
{
SubmitButtonLabel2.Text = "File Accepted.";
}
else
{
SubmitButtonLabel2.Text = "File type not allowed. Please choose another.";
}
}
else
{
SubmitButtonLabel.Text = "Please select a file.";
}
Page:
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server" />
<div>
<asp:FileUpload ID="FileUpload1" runat="server" />
<asp:Button ID="SubmitButton" runat="server" Text="Submit File" OnClick=SubmitButton_Click />
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="always">
<ContentTemplate>
<asp:Label ID="SubmitButtonLabel" runat="Server" />
</ContentTemplate>
<Triggers>
<asp:PostBackTrigger ControlID="SubmitButton" />
</Triggers>
</asp:UpdatePanel>
</div>
</form>
</body>