ASP.Net UpdatePanel doesn't do PostBack - asp.net

I have an ASP.Net page with a long, time-consuming function. I want it to show the "LOADING" word while computing, and show the results when it's done. Here's the code:
<asp:UpdatePanel UpdateMode="Always" runat="server" ID="upanel1">
<ContentTemplate>
<asp:Button ID="btnGetInfo" runat="server" Text="Lekérés" OnClick="btnGetInfo_Click" />
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="btnGetInfo" EventName="Click" />
</Triggers>
</asp:UpdatePanel>
</div>
<asp:UpdateProgress ID="UpdateProgress1" runat="server" AssociatedUpdatePanelID="upanel1">
<ProgressTemplate>
<div>
LOADING</div>
</ProgressTemplate>
</asp:UpdateProgress>
It's almost working(I can see "LOADING" and after the btnGetInfo_Click function ended, "LOADING" disapperrs). I just need a PostBack when it's done.
I've found some similar problem, but the solutions didn't help me.
Thank You for the answers!

What is occurring when you click btnGetInfo is a partial page postback, which refreshes content inside the UpdatePanel ContentTemplate. The reason your GridView is not updating when you call DataBind() is because it is not inside the UpdatePanel ContentTemplate.
Triggering a full-page postback defeats the purpose of an UpdatePanel. I recommend that you put your GridView inside the ContentTemplate to fix the problem.

Related

ASP Update Panel

I implemented an update panel with a treeview control inside. The treeview control will cause a postback via Javascript which leads to the OnNodeChecked being triggered.
I have wrapped this in an UpdatePanel control, but I still get the blinking effect on my page. I also have a scriptManager implemented in the page. Does anyone know what I can do to avoid the flicker?
<asp:UpdatePanel ID="updateTreeViewPanel" runat="server"
ChildrenAsTriggers="true" UpdateMode="Conditional">
<ContentTemplate>
<fieldset>
<asp:TreeView ID="tv_WLG" runat="server"
OnTreeNodeCheckChanged="tv_WLG_TreeNodeCheckChanged"
OnSelectedNodeChanged="tv_WLG_SelectedNodeChanged"
onclick="javascript:postBackByObject(event)"
ShowCheckBoxes="All">
</asp:TreeView>
</fieldset>
</ContentTemplate>
</asp:UpdatePanel>
I would recomend adding a trigger...
<asp:UpdatePanel>
<ContentTemplate>
...your existing code
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="tv_WLG" />
</Triggers>
</asp:UpdatePanel>
The clientside script you're targeting may occur outside the scope of the update panel however. You might try handleing your click event in the codebehind instead.
What you can do is add an onload event to the updatepanel and trigger that using __doPostback() like so. Then whenever the click event fires you can handle it in the onload event of the updatepanel
<asp:UpdatePanel ID="updateTreeViewPanel" runat="server"
ChildrenAsTriggers="true" OnLoad="UpdatePanel_Load" UpdateMode="Conditional">
<ContentTemplate>
<fieldset>
<asp:TreeView ID="tv_WLG" runat="server"
OnTreeNodeCheckChanged="tv_WLG_TreeNodeCheckChanged"
OnSelectedNodeChanged="tv_WLG_SelectedNodeChanged"
onclick="__doPostback('updateTreeViewPanel', '');"
ShowCheckBoxes="All">
</asp:TreeView>
</fieldset>
</ContentTemplate>
</asp:UpdatePanel>
The reason your current method isn't working is because the postback object needs to be an object that is being handled by the update panel. Calling doPostback() with the update panel as the object will trigger the partial postback.

ASP.NET USERCONTROL WITH UPDATE PANEL INSIDE PAGE UPDATE PANEL

I have a master page with the Scrip manager. Have one page that use the master page and inside of this page i have an updatepanel. Inside this update panel i call a UserControl that have inside other updatepanel.
So i have,
MasterPage ->
Page with updatepanel ->
UserControl with update panel
The problem is that the linkbutton event inside the usercontrol updatepanel not fires.
Any help?
<asp:UpdatePanel ID="updPost" runat="server" UpdateMode="Conditional">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="linkComment" EventName="Click" />
</Triggers>
<ContentTemplate>
<asp:LinkButton ID="linkComment" runat="server"
OnClick="linkComment_Click"
CssClass="PostComment" Text="Comment" />
</ContentTemplate>
</asp:UpdatePanel>
This is the code of usercontrol.
Thanks
It looks like showCommentBox() is not returning true.

trigger an async postback for an update panel from a repeater control

I have an ASP.NET Repeater Control inside an UpdatePanel. I need to update another control when clicking in an ImageButton (inside of the Repeater template). The thing is that I can't get that to trigger.
The panel upPanelRotator is refreshed... which I don't want...I just want to call back to server to update another panel - which I'll control from the server.
Any ideas?
<asp:UpdatePanel ID="upPanelRotator" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:Repeater ID="rptRotator" runat="server" OnItemCommand="rptRotator_ItemCommand">
<ItemTemplate>
<asp:ImageButton ID='imgBtn' runat="server" />
</asp:Repeater>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="imgBtn" EventName="ItemCommand" />
</Triggers>
</asp:UpdatePanel>
You should be able to add an async postback trigger to the updatepanel you want to update. Set the control id of the repeater and the "ItemCommand" event as the event name... like this:
<asp:UpdatePanel ID="updatePanel2" runat="server" ChildrenAsTriggers="false" UpdateMode="Conditional">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="repeaterId" EventName="ItemCommand" />
</Triggers>
<ContentTemplate>
...
If PanelA has the trigger button, and you want to update PanelB, you would need to have the async postback trigger on the UpdatePanel surrounding PanelB. The problem is, you need to give the actual ID's of the buttons, which specifying imgButton like you have above won't work (because there could be many in the repeater, and async trigger requires one reference that it won't be able to find). To make this very simpe, wrap everything in the UpdatePanel, and that will make your life easier. Otherwise, you have to add the async postback triggers from code I believe.
I have right now similar situation, and I have do this so that I wrap control inside Repeater in another UpdatePanel, and I set AutoPostBack="true" of that control, and register
< asp:AsyncPostBackTrigger ControlID="imgBtn" EventName="Click"/ >
my only consideration on this is how will a such number of UpdatePanels reflect upon performance. I have small project with few DB entry's but for larger amounts of Data, I would test performance before and after such intervention.

How to force button do a full postback instead of asynchronous postback

In an ASP.NET 4.0 web application, I have a user control that is wrapped by an UpdatePanel (see the code below).
<asp:UpdatePanel ID="UpdatePanel5" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<UC:MyCustomCtrl ID="customCtrl" runat="server" />
</ContentTemplate>
</asp:UpdatePanel>
Obviously, this works great for every ASP.NET control that causes a postback in my user control because it makes it occur asynchronously. However, there is one process that this doesn't work for!
I have an ASP.NET button (Create Report) in the user control that makes an asychronous request to the server. The server then creates an Excel spreadsheet and then places the spreadsheet in the HttpResponse to send back to the client's browser so they can open/save it. However, it blows up at this point because the request to the server is asynchronous and apparently you can't put a binary in the HttpResponse during an asynchronous request.
How do I get around this?
Register this button as synchronous postback control in user control's Page_Load method: ScriptManager.GetCurrent(Page).RegisterPostBackControl(CreateReportButton);
you can add triggers to UpdatePanels that allow full post back. here's an example
<asp:UpdatePanel ID="UpdatePanel5" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<UC:MyCustomCtrl ID="customCtrl" runat="server" />
</ContentTemplate>
<Triggers>
<asp:PostBackTrigger ControlID="btnID" />
</Triggers>
</asp:UpdatePanel>
Make use of the triggers within the update panel to reference the custom control and an event registered on the report button within the control, e.g.
<Triggers>
<asp:PostBackTrigger ControlID="customCtrl" EventName="ReportButtonClicked" />
</Triggers>
Similar to Eric's answer. I have not tried this, but it may work...
<asp:UpdatePanel ID="UpdatePanel5" runat="server">
<ContentTemplate>
<UC:MyCustomCtrl ID="customCtrl" runat="server" />
</ContentTemplate>
<Triggers>
<asp:PostBackTrigger ControlID="customCtrl$btnID" />
</Triggers>
</asp:UpdatePanel>
I did something similar to this a while back for validation controls, so it seems logical that it work here too.
Use your DOM viewer (I use Chrome's element inspector) and see what your button's "NAME" is (not ID). And starting with the portion containing the overall user control's name, use the rest.

asp.net ajax update panel confusion

Well, i have this in my master page
<cc1:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server" ScriptMode="Release" />
And this in a usercontrol
<asp:UpdateProgress ID="updateProgress1" runat="server" AssociatedUpdatePanelID="CustomerListUpdatePanel" DisplayAfter="0" DynamicLayout="false">
<ProgressTemplate>
<asp:Literal ID="loadingLiteral" runat="server" Text="<%$resources:Label,Loading %>" />
</ProgressTemplate>
</asp:UpdateProgress>
<asp:UpdatePanel id="CustomerListUpdatePanel" runat="server" ChildrenAsTriggers="false" UpdateMode="Conditional">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="SearchButton" EventName="Click" />
</Triggers>
<ContentTemplate>
<asp:repeater id="CustomerListRepeater" runat="server">
Problem here is that when i press the SearchButton the update panel updates but the UpdateProgress does not show it self, even if it takes a few seconds.. [somewhat solved by Yuriy Rozhovetskiy].
Problem is that the child buttons inside the updatepanel do not cause a total postback, instead they only reload the update panel, so it seems ChildrenAsTriggers="false" does not work or im miss understanding it.
Im using AjaxControlToolkit 4.1.50731.0.
Edit: also the UpdateProgress seems to display it self if a button is pressed inside the update panel...
Associating an UpdateProgress with an UpdatePanel Control:
The AssociatedUpdatePanelID property has the following effect on
UpdateProgress control behavior:
When the AssociatedUpdatePanelID property is not set, the
UpdateProgress control is displayed for the following postbacks:
Postbacks that originate from inside any UpdatePanel control.
Postbacks that originate from controls that are asynchronous
triggers for any UpdatePanel control.
When the AssociatedUpdatePanelID property is set to an UpdatePanel
control ID, the UpdateProgress control is displayed for postbacks
that originate from inside the associated UpdatePanel control.
Not sure about #Problem 1.
Regarding #Problem 2... I think your understanding might not be correct.
http://msdn.microsoft.com/en-us/library/system.web.ui.updatepanel.childrenastriggers.aspx

Resources