Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1023
  • Last Modified:

I Can't use a FileUpload control in a UpdatePanel (Ajax) ?

I Can't use a FileUpload control in a UpdatePanel (Ajax) ?

This structure don’t have problems.

>          [ MasterPage [ ContentPlaceHolder [ UserControl [ FileUpload ] ] ] ]

But I have this structure:

>          [ MasterPage [ ContentPlaceHolder [ UpdatePanel [ UserControl [ FileUpload ] ] ] ]


With this code I have the error: Object reference not set to an instance of an object
>          Dim uploadImage As System.Drawing.Image
>          Dim Temp As New FileUpload
>          Temp = FileUpload1
>          uploadImage = System.Drawing.Image.FromStream(Temp.PostedFile.InputStream)

I try
FindeControl(“FileUpLoad1”)
UpdatePanel.FindeControl(“FileUpLoad1”)
UserControl.FindeControl(“FileUpLoad1”)
FindControl(“UpdatePanel”).FindeControl(“FileUpLoad1”)
FindControl(“UserControl”).FindeControl(“FileUpLoad1”)

ETC !!!...

But nothing…

Note: ASP.NET, VB.NET, VS2005 and Ajax 1.0
0
darcosys
Asked:
darcosys
  • 8
  • 6
1 Solution
 
Jeff CertainCommented:
You're likely running into an issue with the naming of nested controls. Try:

FindControl(FileUpload1.ClientId)
0
 
darcosysAuthor Commented:
Nop :(

The same error !!!

>      Dim uploadImage As System.Drawing.Image
>      Dim Temp As New FileUpload
>      Temp = FindControl(FileUpload1.ClientID)
>      uploadImage = System.Drawing.Image.FromStream(Temp.PostedFile.InputStream)
0
 
Jeff CertainCommented:
Might be UniqueId instead of ClientId... I can never remeber which to use. And you may have to replace $ with _ or vice-versa.

The easiest way to deal with this is to run your page, look at the source code, find the control you're interested in and note it's name. Then put a breakpoint on the Temp = line... check to see what FileUpload1.ClientId and FileUpload1.UniqueId are...
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
darcosysAuthor Commented:
ClientID      "ctl00_ContentPlaceHolder1_ControlUpLoad1_FileUpload1"      String
UniqueID      "ctl00$ContentPlaceHolder1$ControlUpLoad1$FileUpload1"      String

:( ???
0
 
Jeff CertainCommented:
What's the control name in the web page source? (That is.. run the app, surf to the page, right-click >> view source... this will get you the HTML)
0
 
darcosysAuthor Commented:
<input type="file" name="ctl00$ContentPlaceHolder1$ControlUpLoad1$FileUpload1" id="ctl00_ContentPlaceHolder1_ControlUpLoad1_FileUpload1" class="TextBox" style="width:340px;" />
0
 
Jeff CertainCommented:
So... FindControl(FileUpload1.UniqueID) should get the control.

HOWEVER.... why don't you just refer to it as FileUpload1 on the server side?
Dim uploadImage As System.Drawing.Image = System.Drawing.Image.FromStream(Fileupload1.PostedFile.InputStream)
0
 
darcosysAuthor Commented:
UniqueID and ClientID Don't work

HOWEVER.... why don't you just refer to it as FileUpload1 on the server side? ...   It was my first attempt
0
 
Jeff CertainCommented:
Are you calling FindControl on the page or the user control? You need to ask the parent container for the control IIRC.

What about UserControl.FileUpload1 on the server side?
0
 
darcosysAuthor Commented:
The problem is this...
The UsuerContro it's on the server but Ajax make noise.
If I Put the UserControl on a free Ajax page works perfect.
0
 
darcosysAuthor Commented:
I call the FindControl from de UserControl on the server-side
0
 
Jeff CertainCommented:
I'm out of suggestions then...
0
 
darcosysAuthor Commented:
On the webpage, The same UserControl out of the UpdatePanel works but in the UpdatePanel don't works.
0
 
carmodykCommented:
Read this article, see if this helps:
http://www.codeproject.com/useritems/simpleajaxupload.asp
0
 
darcosysAuthor Commented:
Tk
0

Featured Post

Nothing ever in the clear!

This technical paper will help you implement VMware’s VM encryption as well as implement Veeam encryption which together will achieve the nothing ever in the clear goal. If a bad guy steals VMs, backups or traffic they get nothing.

  • 8
  • 6
Tackle projects and never again get stuck behind a technical roadblock.
Join Now