Drop Down List (in Update Panel) causing FULL PostBack!

喜你入骨 提交于 2019-12-17 19:21:16

问题


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


回答1:


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




回答2:


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"




回答3:


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




回答4:


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!




回答5:


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>



回答6:


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>



回答7:


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:

  1. Drop the AutoPostBack attribute.
  2. 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




回答8:


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




回答9:


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.




回答10:


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);
}



回答11:


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



来源:https://stackoverflow.com/questions/2138565/drop-down-list-in-update-panel-causing-full-postback

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!