Update Panel not updating content

23,221

Solution 1

You have forgotten to set AutoPostback to True on your DropDownList. The default is False.

http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.listcontrol.autopostback.aspx

And if you want to trigger Async-Postback in your UpdatePanel if the User changes the DropDownList, you have to specify an AsyncPostbackTrigger for the UpdatePanel, because the DropDown is outside of it.

<Triggers>
   <asp:AsyncPostBackTrigger ControlID="DropDownList1" EventName="SelectedIndexChanged" />
</Triggers>

Apart from that you need to place the ScriptManager at the beginning as Ed said. Look here for more infos on ASP.NET-Ajax:

http://msdn.microsoft.com/en-us/magazine/cc163354.aspx

Solution 2

Below is the correct markup, just put it to your page:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
  <title></title>
</head>
<body>
  <form id="form1" runat="server">
    Test<br />
    <asp:DropDownList ID="DropDownList1" runat="server" AutoPostback ="True">
      <asp:ListItem>1</asp:ListItem>
      <asp:ListItem>2</asp:ListItem>
   </asp:DropDownList>
   <asp:ScriptManager ID="ScriptManager1" runat="server">
     <Triggers>
        <asp:AsyncPostBackTrigger ControlID="DropDownList1" 
               EventName="SelectedIndexChanged" />
    </Triggers>
  </asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
    <ContentTemplate>
        <br />
        <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
</ContentTemplate>
</asp:UpdatePanel>
</form>

Solution 3

You need to place your Scriptmanager before any controls that will use it.

So place it above your dropdownlist control. You also need to set the AutoPostBack property to true on the dropdownlist for the selectedindexchange event to fire on it.

<body>
    <form id="form1" runat="server">
    <asp:ScriptManager ID="ScriptManager1" runat="server" />

    Test<br />
    <asp:DropDownList ID="DropDownList1" runat="server" AutoPostback="true">
        <asp:ListItem>1</asp:ListItem>
        <asp:ListItem>2</asp:ListItem>
    </asp:DropDownList>

    <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
        <ContentTemplate>
            <br />
            <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
    </ContentTemplate>
    </asp:UpdatePanel>
    </form>
</body>
Share:
23,221
surpavan
Author by

surpavan

Just a guy interested in coding and IT infrastructure management and Administration. MBA and MCTS (Server 2008 Networking) Microsoft Office Specialist (MOS) - Excel 2010 Expert Trained in MCITP, CCNA, CCSE

Updated on December 02, 2020

Comments

  • surpavan
    surpavan over 3 years

    I was trying this from some time, but I am not able to get around it. Following is the code of the aspx page display:

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
    </head>
    <body>
        <form id="form1" runat="server">
        Test<br />
        <asp:DropDownList ID="DropDownList1" runat="server">
            <asp:ListItem>1</asp:ListItem>
            <asp:ListItem>2</asp:ListItem>
        </asp:DropDownList>
        <asp:ScriptManager ID="ScriptManager1" runat="server">
        </asp:ScriptManager>
        <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
            <ContentTemplate>
                <br />
                <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
        </ContentTemplate>
        </asp:UpdatePanel>
        </form>
    </body>
    </html>
    

    Following is the code for the button1 click event:

    Public Class WebForm1
        Inherits System.Web.UI.Page
    
        Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    
        End Sub
    
        Protected Sub DropDownList1_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs) Handles DropDownList1.SelectedIndexChanged
            Label1.Text = DropDownList1.SelectedIndex
    
            UpdatePanel1.Update()
    
        End Sub
    End Class
    

    Could you please tell me what I missed out.