Drop Down List (in Update Panel) causing FULL PostBack! - asp.net

I have a problem with my AJAX and ASP.NET 3.5 :(
Problem is really weird, as I'm using the same thing on different page and it works fine in there, but on this specific page, this is not working.
Here's what I have:
<asp:UpdatePanel ID="upMain" runat="server" UpdateMode="Conditional" Visible="true" RenderMode="Inline">
<ContentTemplate>
<asp:DropDownList ID="ddlNewService_PortTelco" runat="server" Width="250" CssClass="dropdown" AutoPostBack="true" OnSelectedIndexChanged="Provision_PortedTelcoChanged"></asp:DropDownList>
</ContentTemplate>
</asp:UpdatePanel>
On the way before the DropDown there is one DIV (html one), and then few asp:Panels.
I do not understand why this is causing a FULL POST BACK ?!
Any ideas ? Thanks

i had the same problem... altho it's not showing in the copied code here, check to make sure you don't have any controls with ClientIDMode=Static within the updatepanel .... make them inherit
at least any controls that may trigger a postback

Me having the same problem...
CHECK your WEB.CONFIG
<xhtmlConformance mode="Legacy"/>
for this line.. and JUST REMOVE IT!!
Worked for me. Thanks http://andrew-murphy.co.uk/?p=152

You have your drop down list with an AutoPostBack set to true. That's why you have it post back instead of AsyncPostBack, if that is what you wanted.
Remove the AutoPostBack=true from the dropdownlist
and set an Async trigger for your UpdatePanel set to the dropdownlist and its eventname="SelectedIndexChanged"

Excuse my lack of programing skills :| It all worked all the time, but because one of the actions page "looked" like it's POST BACKED, when it wasn't. What a shame!!!
Sorry for waisting Your time!

Setting the AutoPostBack attribute to true should be enough to cause a partial postback but it's not what happens and a full postback is triggered instead as you correctly described.
The following workaround works for me:
Drop the AutoPostBack attribute.
Trigger the postback using the "onchange" client side event.
This is how the original DropDownList should look like:
<asp:DropDownList ID="ddlNewService_PortTelco" runat="server" Width="250" CssClass="dropdown" OnChange="javascript:WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions(this.name, '', true, '', '', false, true))" OnSelectedIndexChanged="Provision_PortedTelcoChanged"></asp:DropDownList>
For more details regarding the WebForm_PostBackOptions parameters see below:
function WebForm_PostBackOptions(eventTarget, eventArgument, validation, validationGroup, actionUrl, trackFocus, clientSubmit)
http://msdn.microsoft.com/en-us/library/system.web.ui.postbackoptions_members(v=VS.90).aspx

If you have some asp component with Autopostback="true" and ClientIdMode="Static", you have to use the trigger.
Like this:
<asp:UpdatePanel ID="upPrinceOffuce" runat="server">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="ddlPrintOffice" EventName="SelectedIndexChanged" />
</Triggers>
<ContentTemplate>
<asp:DropDownList ID="ddlPrintOffice" runat="server" ClientIDMode="Static" AutoPostBack="true" ...blah blah
</asp:DropDownList>
</ContentTemplate>
</asp:UpdatePanel>

How do you bind your DropDown? The code that you have provided works on my side with static items. Perhaps it is something in the other controls that is causing the problem.
I have noticed that your UpdatePanel has its UpdateMode property set to conditional, however you haven't defined any triggers.You can try to explicitly set that the update panel should perform async postback when your dropdown triggers its selectedIndexChanged event. You can use something like the following markup:
<asp:UpdatePanel ID="upMain" runat="server" UpdateMode="Conditional" Visible="true"
RenderMode="Inline">
<ContentTemplate>
<asp:DropDownList ID="ddlNewService_PortTelco" runat="server" Width="250"
AutoPostBack="true" OnSelectedIndexChanged="Provision_PortedTelcoChanged">
</asp:DropDownList>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="ddlNewService_PortTelco" EventName="SelectedIndexChanged" />
</Triggers>
</asp:UpdatePanel>

Set AutoID value to ClientIDMode property. It worked for me. I have had different behaviour in different browsers (i.e. Google chrome and Firefox).

Had the same problem when the Dropdownlist Autopostback attribute was set to true
and fixed the problem by adding the dropdownlist ID to the updatepanel trigger

I had this problem. My Dropdownlist was inside of an HTML table and I had my Update Panel wrapped around two individual rows. I fixed the problem by wrapping the Update Panel around the entire table rather than just the two rows.

One alternative to fix this issue is:
Declare the library
using AjaxControlToolkit;
Then you can do something on these lines
private void InitControl()
{
//FIX - DROP DOWN
ToolkitScriptManager scrManager = (ToolkitScriptManager)Page.Master.Controls[0].Controls[0].FindControl("manScript");
scrManager.RegisterAsyncPostBackControl(ddlNewService_PortTelco);
}

Related

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.

All UpdatePanels posting back at the same time

I have a C# .net 4.0 website project with a fairly complicated filtered search page on it. There are multiple UpdatePanels that are added within a Repeater. When one UpdatePanel does a postback - all the other UpdatePanels also postback at the same time.
This becomes a problem because there can be lots and lots of UpdatePanels dependent on the number of items the user chooses to view. I know UpdatePanels are not ideal - I didn't write this but have to try and fix it quickly!
There is LandingPage that holds an UpdatePanel with a Repeater control inside. Within the repeater is a user control called Article. The Article control contains some HTML and a second user control called Save. The Save control has an UpdatePanel too.
The problem I have is that only the first btnSave event gets raised. So if I click "btnSave" it works but all subsequent button click events do not fire.
I have also noticed that ALL instances of the UpdatePanel in the Save control postback at the same time - is this normal?
So a simplified view of the page is like so:
LandingPage.aspx
<asp:UpdatePanel ID="pnl" runat="server" UpdateMode="Conditional" ChildrenAsTriggers="false">
<ContentTemplate>
<asp:Repeater ID="resultsRep" runat="server">
<ItemTemplate>
<uc:Article id="Article1" runat="server" />
</ItemTemplate>
</asp:Repeater>
<asp:Button id="btnLoadMore" runat="server" Text="Load More" />
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="btnLoadMore" EventName="Click" />
</Triggers>
<asp:UpdatePanel>
Custom User Control "Article"
<asp:PlaceHolder ID="ArticlePanel" runat="server">
<!-- Assorted HTML stuff here -->
<uc:Save id="Save1" runat="server" />
</asp:PlaceHolder>
Custom User Control "Save"
<asp:UpdatePanel ID="ctl" runat="server" UpdateMode="Conditional" ChildrenAsTriggers="True">
<ContentTemplate>
<asp:LinkButton ID="btnSave" runat="server" OnClick="btnSave_Click" CausesValidation="False" Text="Save" />
</ContentTemplate>
</asp:UpdatePanel>
Thanks in advance as always.
EDIT
After further investigation, using Firebug console I found that the subsequent postbacks don't occur because the following error is thrown:
505|error|500|Invalid postback or callback argument.
Event validation is enabled using <pages enableEventValidation="true"/> in configuration or <%# Page EnableEventValidation="true" %> in a page.
For security purposes, this feature verifies that arguments to postback or callback events originate from the server control that originally rendered them.
If the data is valid and expected, use the ClientScriptManager.RegisterForEventValidation method in order to register the postback or callback data for validation.|
So it seems somehow I am posting back something dodgy?
The problem was down to the use of nested UpdatePanels. I don't know where the error itself actually comes from but after trial and error I figured out that the parent UpdatePanel wasn't configured properly.
The parent UpdatePanel should have been like so :
<asp:UpdatePanel ID="pnl" runat="server" UpdateMode="Always" ChildrenAsTriggers="true">
The difference being UpdateMode="Always" and ChildrenAsTriggers="true". The UpdateMode tells the parent UpdatePanel to refresh when any of the children reload. The ChildrenAsTriggers attribute allows child UpdatePanels to cause the refresh of the parent.
So now it works - mostly. I still have the issue of every single UpdatePanels posting back everytime. Its really inefficient but I can't seem to stop it.

UpdatePanel inside a Repeater - update all rows

I'm trying to speed up my Repeater so that not as much HTML has to be resent via the AJAX UpdatePanel on each call.
So here's what I have (a very much simplified version):
<asp:Repeater ID="rptContactSteps" runat="server">
<ItemTemplate>
<p>Script:<br /><%#mobjSDIT.FormatText(Eval("script"))%></p>
<p>Notes:<br /><%#mobjSDIT.FormatText(Eval("notes"))%></p>
<asp:UpdatePanel ID="upStep" runat="server" UpdateMode="Conditional">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="rptContactSteps" EventName="ItemCommand" />
</Triggers>
<ContentTemplate>
<p>Contact/Step Notes:<br /><%#mobjSDIT.FormatText(Eval("contact_step_notes"))%></p>
<asp:ImageButton ID="btnSaveAndCompleteLastStep" runat="server" ImageUrl="~/images/content/buttons/save-and-complete-button.png" CommandArgument='<%#Eval("step_contact_tie_id")%>' />
</ContentTemplate>
</asp:UpdatePanel>
</ItemTemplate>
</asp:Repeater>
So, when I click 'btnSaveAndCompleteLastStep' I want all the UpdatePanel in 'rptContactSteps' to update. Having the UpdatePanel inside the ItemTemplate should help prevent having to re-load the html/text that populates the Eval("script") & Eval("notes"), since the value of these variables could be very large and over a 3G connection this could be very costly (in time & money).
I though by adding the async trigger it'd work as I have used this type of trigger before, but not when inside the Repeater. Currently the UpdatePanels aren't getting updated at all, except from the one from which the button was pressed.
Any ideas anyone?
They aren't getting updated except by the one that is called because the update mode is set to conditional, and by default the ChildrenAsTriggers is set to true. So if you want them all to update when one of them is changed, then you will need to find each of the update panels in each of the repeater items and call .Update() on the update panel, or you can change the update mode to "Always", or just wrap your repeater in an update panel instead of wrapping just the items.
Does that make sense? If not I can expand.
That behavior sounds ok to me because postback from within an updatepanel will not update anything outside of it by default.
One way you can try is on your btnSaveAndCompleteLastStep click , find each updatepanel in the repeater items and call Update() on it.

Set an async trigger for an Update Panel with a GridView asp:ButtonField

What is correct sytnax for setting an AsyncPostBackTrigger for an UpdatePanel with an asp:ButtonField from an GridView control?
I need to set an 'AsyncPostBackTrigger' for each asp:ButtonField in my GridView
Here is my source code
<asp:UpdatePanel ID="MyUpdatePanel" runat="server" ChildrenAsTriggers="true" UpdateMode="Conditional">
<Triggers>
</Triggers>
<ContentTemplate>
<asp:GridView ID="MyGridView" runat="server" AutoGenerateColumns="false">
<Columns>
<asp:ButtonField ButtonType="Link" CommandName="Button1" SelectText="Click Me!" />
<asp:ButtonField ButtonType="Link" CommandName="Button2" SelectText="No Click Me!" />
</Columns>
</asp:GridView>
</ContentTemplate>
</asp:UpdatePanel>
Update
I need to keep the UpdateMode and ChildrenAsTriggers attributes set to true because the I have other button contained within the UpdatePanel that do not refresh the UpdatePanel control
The ChildrenAsTriggers property being set to true will cause any control that causes a postback within the update panel to cause it to refresh. You would only need to use the triggers element if you had a control outside of the update panel you wished to use to trigger the refresh of that update panel. You don't even need the triggers element in this instance.
Everything that Lance Harper mentioned is true, but you also need to remove the following attribute:
UpdateMode="Conditional"
Having that attribute in place will prevent the automatic wire-up of your client side events. Essentially you are telling ASP.Net that you are going to do this yourself.
Could you use a template field instead of a command field, and forcibly update (UpdatePanel.Update()) the panel when the command button is clicked?

Why does the Update Panel do a full post back for custom control?

I have a rather complex custom control - the custom control has a couple of update panels in it.
I am trying to use the control like this inside of an update panel:
<asp:UpdatePanel ID="up1" runat="server">
<ContentTemplate>
<asp:Button ID="btn1" runat="server" Text="Sample Button" /> <asp:Label ID="lblTime" runat="server"></asp:Label>
<cc1:MyCustomControl ID="MyCustomControl1" runat="server" >
</cc1:MyCustomControl>
</ContentTemplate>
</asp:UpdatePanel>
When I click the button in the update panel, it does an async post back and there is no screen "flicker" When I click a button in my custom control the page flickers and does a full post back.
Inside the custom control, there are update panels that are trying to do full postbacks (based on triggers).
How can I make the page level UpdatePanel not do a full postback no matter what is going in inside of the custom control?
Have you thought about explicitly setting an asp:AsyncPostBackTrigger with the btn1 control in the up1 UpdatePanel control.
<asp:UpdatePanel ID="up1" runat="server">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="btn1" EventName="Click" />
</Triggers>
<ContentTemplate>
<asp:Button ID="btn1" runat="server" Text="Sample Button" />
<asp:Label ID="lblTime" runat="server"></asp:Label>
<cc1:MyCustomControl ID="MyCustomControl1" runat="server" />
</ContentTemplate>
</asp:UpdatePanel>
Edit: How you tried to explicitly call the Update method in the button's OnClick event for the Update Panel? This includes the Update panels embedded within the custom control.
Figured out the solution similar issue to this: How can I get an UpdatePanel to intercept a CompositeControl's DropDownList
Except my control causing the postback was in an updatepanel with a full postback trigger. I was able to pull that control out so it was not nested with in update panels and that resolved it.
I would first look if there is some other issue with the custom control causing the full page postback, as in any case what should be happening is that the whole update panel refreshes (still with ajax).
After that, just look at the Nesting UpdatePanel Controls section of this:
http://msdn.microsoft.com/en-us/library/bb398867.aspx#
Also make sure to have the ScriptManager control with the property EnablePartialRendering set to true.
On the UpdatePanel, set the property ChildrenAsTriggers="true". This tells the UpdatePanel to intercept all PostBack invocations that originate from inside the UpdatePanel.
You may want to also explore the UpdateMode property, which determines what kinds of events trigger an update. (By default, an UpdatePanel will refresh if any other panel on the screen gets refreshed. This threw me for awhile until I realized what was going on.)

Resources