File upload inside a usercontrol inside an updatepanel

L

Leon Mayne

Having a bit of trouble here. I know that if you want to use a fileupload
control inside an AJAX update panel then you need to create a trigger for
the control that performs the uploading postback to the updatepanel, but the
problem is, I have an update panel inside a web usercontrol, and the
usercontrol is sitting inside an updatepanel on the host page. I therefore
can't add a trigger to the control directly, as the host page has no access
to the button within the usercontrol.

Does anyone know a way round this?
 
B

bruce barker

as you don't want the fileupload to trigger a async postback (it needs to do
a browser postback to work), just be sure its not a trigger to the panel its
inside.

-- bruce (sqlwork.com)
 
T

Teemu Keiski

ScriptManager.RegisterPostBackControl does the equivalent in code (you get
reference to SM with ScriptManager.GetCurrent())

"Use the RegisterPostBackControl method to register postback controls inside
an UpdatePanel control as triggers. Controls that are registered by using
this method update a whole page instead of updating only the UpdatePanel
control's content. Registering a postback control with this method outside
an UpdatePanel control has no affect because by default these controls do
not perform asynchronous postbacks"
 
L

Leon Mayne

Teemu Keiski said:
ScriptManager.RegisterPostBackControl does the equivalent in code (you get
reference to SM with ScriptManager.GetCurrent())

"Use the RegisterPostBackControl method to register postback controls
inside an UpdatePanel control as triggers. Controls that are registered by
using this method update a whole page instead of updating only the
UpdatePanel control's content. Registering a postback control with this
method outside an UpdatePanel control has no affect because by default
these controls do not perform asynchronous postbacks"

Damn, almost worked, but it looks like neither the file upload control nor a
panel implement an appropriate interface:

"Control with ID 'pnlUpload' being registered through
RegisterAsyncPostBackControl or RegisterPostBackControl must implement
either INamingContainer, IPostBackDataHandler, or IPostBackEventHandler."
 
L

Leon Mayne

bruce barker said:
as you don't want the fileupload to trigger a async postback (it needs to
do
a browser postback to work), just be sure its not a trigger to the panel
its
inside.

OK, do you know how to make just the file upload control not a trigger? The
rest of the controls in the usercontrol need to be triggers, but because
there is an extra layer between the update panel and the file upload control
I can't directly reference one from the other.

I guess I could make the control public, but wouldn't this get overwritten
as soon as the designer file is updated?
 
L

Leon Mayne

Leon Mayne said:
Damn, almost worked, but it looks like neither the file upload control nor
a panel implement an appropriate interface:

"Control with ID 'pnlUpload' being registered through
RegisterAsyncPostBackControl or RegisterPostBackControl must implement
either INamingContainer, IPostBackDataHandler, or IPostBackEventHandler."

Oh wait, I registered the wrong control. I changed it to register the button
instead and it worked:

Dim scmCurrent As ScriptManager = ScriptManager.GetCurrent(Me.Page)
If scmCurrent IsNot Nothing Then
scmCurrent.RegisterPostBackControl(Me.btnUpload)
End If

Thanks Teemu.
 

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,968
Messages
2,570,153
Members
46,699
Latest member
AnneRosen

Latest Threads

Top