I have an update panel that contains a repeater that calls a user control into each row. When I click a button inside the user control, the page does not refresh at all, only when I reload it completely. How can I make the update panel refresh from user control's button click?
Update parent updatepanel from within usercontrol
asp.netcontrolsupdatepanel
Related Solutions
An UpdatePanel completely replaces the contents of the update panel on an update. This means that those events you subscribed to are no longer subscribed because there are new elements in that update panel.
What I've done to work around this is re-subscribe to the events I need after every update. I use $(document).ready()
for the initial load, then use Microsoft's PageRequestManager
(available if you have an update panel on your page) to re-subscribe every update.
$(document).ready(function() {
// bind your jQuery events here initially
});
var prm = Sys.WebForms.PageRequestManager.getInstance();
prm.add_endRequest(function() {
// re-bind your jQuery events here
});
The PageRequestManager
is a javascript object which is automatically available if an update panel is on the page. You shouldn't need to do anything other than the code above in order to use it as long as the UpdatePanel is on the page.
If you need more detailed control, this event passes arguments similar to how .NET events are passed arguments (sender, eventArgs)
so you can see what raised the event and only re-bind if needed.
Here is the latest version of the documentation from Microsoft: msdn.microsoft.com/.../bb383810.aspx
A better option you may have, depending on your needs, is to use jQuery's .on()
. These method are more efficient than re-subscribing to DOM elements on every update. Read all of the documentation before you use this approach however, since it may or may not meet your needs. There are a lot of jQuery plugins that would be unreasonable to refactor to use .delegate()
or .on()
, so in those cases, you're better off re-subscribing.
For solve this problem, Please see the following step.
- Add ajax-upload to your detail view.
- iframe-based uploader like Resource#1.
- Silverlight-based & Flash-based uploader. I like this technique because it doesn't require any server-side script for display current upload status. But in HTML5, you can create this without using any web browser plug-in.
- Commercial uploader like Resource#2. that use hidden iframe for uploading.
Upload file to temporary location.
- System response the temporary location. Next, client keep temporary location in hidden input in detail form.
- Keep temporary location with session_id. You can store it in database or Session variable depend on your framework.
When you click on the save button, the system will move the files to their real location
Note. System will automatically delete the expired file from the temporary location.
Resource
Update
After almost one year, I just found a great 3rd-parties control for this question. This is an open source plug-in of jQuery. It name Plupload that allows you to upload files using HTML5, Silverlight, Flash or normal forms and it provide some unique features such as upload progress, image resizing and chunked uploads.
Best Answer
Phairoh is correct that your button needs to successfully cause a PostBack.
There are three things that affect when a UpdatePanel is updated:
UpdateMode
property - This takes two possible values,Always
andConditional
.Always
then any postback o the page will cause the UpdatePanel to update.Conditional
then the UpdatePanel is only updated when the UpdatePanel'sUpdate
method is called or when one of the UpdatePanel's triggers does a postback.Triggers
proroperty - Defines which controls will cause the UpdatePanel to be updated whenUpdateMode
is set toConditional
.ChildrenAsTriggers
property - This is a boolean value that determines if child controls of the UpdatePanel are automatically considered triggers without having to be added to theTriggers
collection.Because your button is in a UserControl it won't be easy to add the control to the
Triggers
collection or to have the button call the Update method on the UpdatePanel that is not inside the UserControl.Because your UpdatePanel contains the UserControl's your best bet is to enable
ChildrenAsTriggers
. If this doesn't work try setting theUpdateMode
property toAlways
. If this still doesn't work then Phairoh is probably correct and your Button isn't posting back.