I have scenario, I have two update panels on the page (both have update mode='conditional'). If I update one update panel the other is automatically updated. This is first problem.
I am using UpdatePanelAnimationExtender. If one update panel is updated, that don’t have updatepanelAnimationExtender other one also updated and that have updatepanelAnimationExtender, OnUpdatingUpdatePanel(); event is fired.
As the documentation of updatepanelAnimationExtender says:
http://www.asp.net/AJAX/AjaxControlToolkit/Samples/UpdatePanelAnimation/UpdatePanelAnimation.aspx
OnUpdating - Generic animation played as when any UpdatePanel begins updating
OnUpdated - Generic animation played after the UpdatePanel has finished updating (but only if the UpdatePanel was changed)
Problem: OnUpdating fired and it worked backend and not finished because onUpdated only fired when an UpdatePanel Changed
"Add 2 update panel on page, set updatemode='conditional' for both and add load event for both updatepanel and set breakpoint for both load event and add 1 button and then add Asyn trigger for button click on 1 update panel.... you will notice when you hit button, it should load only triggered update panel and 2nd one remain unchanged, but 2nd updatepanel is load event also fired"
This will happen only if the button is inside the 2'nd updatepanel? If not, then I dont think it will update the second update panel. Could you confirm if the button is inside or outside the second updatepanel?
I just had this same issue. Two update panels on the same page that are NOT nested and have UpdateMode="Conditional". Just realize that when one update panel on a page triggers a partial postback, all update panels will get the updating event triggered. If you have an UpdatePanelAnimationExtender hooked up to UpdatePanel A, and a partial postback is triggered for an unrelated UpdatePanel B, both will get the updating event triggered, and the animation for UpdatePanel A will only run the OnUpdating part and not the OnUpdated part (so basically the animation will run half way).
This is how I fixed this issue:
Determine which update panel was triggered. This can be found by getting the value of the form variable for the script manager. The update panel in question will be mentioned in the string. Use this info to perform an action based on your needs.
// Variable to hold ScriptManager. Just slap this in the class for the page.
private ScriptManager scriptManager;
// Get the ScriptManager. Put this in Page_Init handler.
// If you have the ScriptManager on the same page, just refer to it directly.
// If you have it on the master page, you can get a reference to it like so.
// The second line shows one way you can get a reference to the ScriptManager from
// a user control.
// FYI, the same code applies to a ToolkitScriptManager.
scriptManager = ScriptManager.GetCurrent(this);
// scriptManager = ScriptManager.GetCurrent(HttpContext.Current.Handler as Page);
// This function checks whether an UpdatePanel is being updated
private Boolean IsUpdatePanelUpdating(String sUPID)
{
String sUpdateValue = Request.Form[Request.Form.AllKeys.Where(s => s.EndsWith(scriptManager.ClientID)).FirstOrDefault()] ?? String.Empty;
return sUpdateValue.Contains(sUPID);
}
// This is code you can put somewhere (say within OnLoad handler) to make an
// UpdatePanel A get updated even if an unrelated UpdatePanel B is currently being
// updated.
if (!IsUpdatePanelUpdating(upA.ClientID))
upA.Update();
I hope this helps someone.
Related
Allright so I have a slight issue when I want to load some basic usercontrols which contain an UpdatePanel inside to another page which is an usercontrol.
The set up:
Whenever an user clicks on a button a pop-up shows up containing some basic info on a certain person and a tab which contains the companies he worked for. The amount of companies he/she works for can range from 1 to 4~, so I do a query then for each company I get I add a view to a multiview, this view contains multiple simple user controls (Textfields inside an updatepanel). Now whenever I go to the page I get this error:
Cannot unregister UpdatePanel with ID 'UpdatePanel2' since it was not registered with the ScriptManager. This might occur if the UpdatePanel was removed from the control tree and later added again, which is not supported. Parameter name: updatePanel
Now I know this is a common error caused by generating UpdatePanels dynamically which aren't registered with the ScriptMaster. I can't add a PreInit event handler to the page which adds the UserControls with the UpdatePanels since it's an UserControl itself.
My question is:
How can I get rid of this nasty error in a not so nasty way e.g. not a hardcoded sub routine which adds the UpdatePanel to the scriptmaster
You could define the functionality you want to add inside your user controls. I have done the same in the past, adding the following, inside of my user control.
override protected void OnInit(EventArgs e) {
// your code here
}
Add a ScriptManager on your MasterPage before the UpdatePanel. And your updatePanel is a bit confusing so might change it as well. :)
I have a page that creates a list, a button and a textfield dynamically in the Page_Load handler. When you click the button, the text from the textbox is added to the list and everything is re-created by clearing the controls collection of the page and then re-adding all required controls.
So basically, the button gets created two times for every Postback (first in the Page_Load, then in the Button_Click handler).
This only works on the first PostBack. If you try it a second time, the Button_Click handler never gets called (although the dynamic controls get re-created on PostBack).
What am I missing here? Is it possible that the Button_Click event is still wired-up to the first button (the one that was thrown away via Controls.Clear() )?
Page_Load is too late to create the button; it should be in Page init or preinit. If you readd the button, after clearing it, you have to readd the event handler too.
I have finally figured out what the cause of the problem is: when the controls are created more than once, the Event-Handlers (e.g. Button.Click) are also registered more than once. I don't know why, but this causes all of them to stop working. In other words, the events of the disposed Buttons somehow interfer with the events of the actual Buttons.
I solved this by ensuring that the handlers are only registered once (in the Page_Load).
I have a web page that initially loads a drop down list. When an item is selected from the list, a web form is dynamically created during an update panel async postback.
I added watermark extenders to some of the textboxes, but the watermark does not display when the page is first updated. If I focus in and then out of one of the textboxes, the watermark then appears and seems to work fine. From examining the source, I saw that the client side creation of the watermark was being attached to the init event of Sys.Application on the client.
Here's where I'm getting confused.
1. I added a handler to the client side page Sys.Application.initialize event to see if it was called during the life cycle of an async postback. It didn't appear to fire the event.
2. I tried to raise the initialize event by adding a handler to the PageRequestManager End Request method, but the flags that check if the page was already initialized were set, so none of the individual handlers were fired.
3. After 1 & 2, I thought maybe the watermark extender was somehow being lazy loaded when I applied focus to it. So I put the $create statement that is supposed to be executed in the initialize event in the End Request event of the PageRequestManager. The client script threw an error because the watermark extender was apparantly already created.
I'm not sure what the resolution here is, outside of writing my own watermark code. Is this a limitation (will the extender only function correctly if created in the initial request for the page)? And what about the init event? I can't see it firing, but if the extender was already created, it must have???
Any help would be appreciated. Thanks.
The watermark extension gives headaches to others too. I'd suggest taking a look at a jquery watermark plugin http://jquery-watermark.googlecode.com/
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?
Phairoh is correct that your button needs to successfully cause a PostBack.
There are three things that affect when a UpdatePanel is updated:
The UpdateMode property - This takes two possible values, Always and Conditional.
If it is set to Always then any postback o the page will cause the UpdatePanel to update.
If it is set to Conditional then the UpdatePanel is only updated when the UpdatePanel's Update method is called or when one of the UpdatePanel's triggers does a postback.
The Triggers proroperty - Defines which controls will cause the UpdatePanel to be updated when UpdateMode is set to Conditional.
The 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 the Triggers 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 the UpdateMode property to Always. If this still doesn't work then Phairoh is probably correct and your Button isn't posting back.
Sometimes solving this problem not really convenient with Triggers. So here is another fancy approach which could be used even from your user controls without any knowledge about Update Panel:
var scriptManager = ScriptManager.GetCurrent(Page);
if (scriptManager != null)
scriptManager.RegisterPostBackControl(SomeControlID);
Are you sure your buttons on your user control are attempting to do a postback? I haven't used update panels in a while (and I'd actually recommend avoiding them) but if I recall correctly they will refresh whenever a postback is done within them. This means that your buttons must be Asp:Buttons (or similar controls that cause postback) and not have some kind of javascript on them that would not allow their action to continue (such as a return false).
If you have an update panel, that displays a number in its Load method, and a button as a trigger, and you make the button have an onclick method that increments the number, the update panel will not update when you click it.
This is because the update panels Load method runs before the OnClick method, so it draws the number on the screen before it increments it.
At the moment I get around this by using the scriptmanager to tell me which button or whatever caused the update panel to trigger, and then I use that to run the increment method before it renders, which works.
It sucks though because it renders onclick methods for buttons obselete if you want immediate feedback from them, and fills your load method with IF statements.
Am I missing something or is this the intended way update panels work?
That's just the order of the events in the page cycle, and that is the same regardless if you are using update panels or not.
You can use the Page_PreRender event instead to put the number in the page. It occurs after
the click event but before the page is rendered as HTML.