Sanjay
Sanjay

Reputation: 33

AsyncPostBackTrigger is not updating the update panel

I am using an update panel inside a user control in ASP.NET (.ascx file). Below is my HTML markup

<asp:ScriptManager EnablePartialRendering="true"
                   ID="ScriptManager1" runat="server"></asp:ScriptManager>
<div>        
    <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional" ChildrenAsTriggers="true" >
        <ContentTemplate>
            <asp:Label ID="Label1" runat="server" /><br />
            <asp:Button ID="Button1" runat="server" Text="Update Panel" OnClick="Button1_Click" />                
        </ContentTemplate>
        <Triggers>
            <asp:AsyncPostBackTrigger ControlID="Button1" EventName="Click">
           </asp:AsyncPostBackTrigger>
        </Triggers>
    </asp:UpdatePanel>
</div>

here is my code-behind

public partial class sample: System.Web.UI.Control
{
    protected void Button1_Click(object sender, EventArgs e)
    {

        Label1.Text = DateTime.Now.ToLongTimeString();
        UpdatePanel1.Update();
    }

}

If I use PostBackTrigger, then it works fine but posts back the entire page (that's something I don't want) I just need to refresh the update panel.

And here is my aspx page markup (it's Sitecore driven site so all the sublayouts are loaded into Sitecore placeholders)

<form id="form2" runat="server">
    <section class="page">
        <sc:Placeholder runat="server" ID="mainPlaceholder" Key="content" />
    </section>
</form>

I'm sorry, cannot post the entire page due to some security reasons

Thank you

Upvotes: 1

Views: 2454

Answers (2)

Sanjay
Sanjay

Reputation: 33

Finally, I found a solution to fix this issue. My entire HTML markup remains same just need to comment or take off the triggers. I just commented the inner HTML of tag and it everything worked as expected.

Upvotes: 1

wazz
wazz

Reputation: 5068

a few things to try. (it works fine for me.)

  1. make sure you do not have 2 script managers, one on the page and one on the control. one on the aspx page is enough.
  2. delete the user control from the aspx page and add the user control again. drag your user control to the aspx page to make sure it's registered at the top of the page.
  3. remove the triggers; you don't need them.

you are also setting some properties that are equal to the default values so you can remove them:

<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>

<asp:UpdatePanel ID="UpdatePanel1" runat="server">
    <ContentTemplate>
        <asp:Label ID="Label1" runat="server" /><br />
        <asp:Button ID="Button1" runat="server" Text="Update Panel"
            OnClick="Button1_Click" />                
    </ContentTemplate>
</asp:UpdatePanel>

protected void Button1_Click(object sender, EventArgs e)
{
    Label1.Text = DateTime.Now.ToLongTimeString();
    //UpdatePanel1.Update();
}

Upvotes: 0

Related Questions