Archive for the ‘ASP.Net’ Category
Any control residing inside an updatepanel automatically causes a partial refresh and updates the update panel. However, sometimes you want to trigger an update on an update panel from a control that is outside of the control panel and that is where triggers come in.
<asp:UpdatePanel ID="MyUpdatePanel" UpdateMode="Conditional" runat="server"> <Triggers> <asp:AsyncPostBackTrigger ControlID="MyButton" EventName="OnClick" /> </Triggers> <ContentTemplate> </ContentTemplate> </asp:UpdatePanel>
This works fine a dandy however if you are in some sort of template e.g. a create user wizard template you are bound to get the following error
A control with ID ‘MyButton’ could not be found for the trigger in UpdatePanel ‘MyUpdatePanel’.
My first approach was to use the ScriptManager RegisterAsyncPostBackControl
<li>The script manager is accessed via a property on the master page
<li>The MyButton is referenced via a findcontrol call
This does not work since the postback is not tied to an update panel and causes a full postback. The solution is to register a trigger on the update panel from the code behind page like so
UpdatePanel MyUpdatePanel = ControlFinder.FindChildControl<UpdatePanel>(Page, "MyUpdatePanel"); AsyncPostBackTrigger MyUpdatePanelTrigger = new AsyncPostBackTrigger(); MyUpdatePanelTrigger.ControlID = MyButton.UniqueID; MyUpdatePanelTrigger.EventName = "Click"; MyUpdatePanel.Triggers.Add(MyUpdatePanelTrigger);
The two tricks are
2) Have AutoPostBack set to true on the asp.net textbox control
Instead of using the reload command use this instead document.location.href=’url’; it has the same effect as the document.location.reload() except IE does not throw the error since you are reloading the page explicitly instead of having the brower reload the page for you and throwing up the warning.