开发者

Why doesn't AJAX UpdatePanel work in ASP.NET 2.0 Web Site template?

开发者 https://www.devze.com 2022-12-20 05:10 出处:网络
I\'m just getting into AJAX (little late I know) and am walking through some of the tutorials on the ASP.NET/AJAX site. One thing I\'ve noticed is that I cannot get the UpdatePanel to work in the ASP.

I'm just getting into AJAX (little late I know) and am walking through some of the tutorials on the ASP.NET/AJAX site. One thing I've noticed is that I cannot get the UpdatePanel to work in the ASP.NET Web Site template. I can use the EXACT same markup, code, and web.config in the AJAX 1.0-Enabled ASP.NET 2.0 template and everything works as expected.

Markup:

    <%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %><html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
               <asp:ScriptManager EnablePartialRendering="true"
                    ID="ScriptManager1" runat="server"></asp:ScriptManager>
               <div>
                    <asp:UpdatePanel ID="UpdatePanel1" runat="server"
                         UpdateMode="Conditional">
                         <ContentTemplate>
                              <asp:Label ID="Label1" runat="server" /><br />
                              <asp:Button ID="Button1" runat="server"
                                   Text="Update Both Panels" OnClick="Button1_Click" />
                              <asp:Button ID="Button2" runat="server"
                                   Text="Update开发者_JAVA百科 This Panel" OnClick="Button2_Click" />
                         </ContentTemplate>
                    </asp:UpdatePanel>
                    <asp:UpdatePanel ID="UpdatePanel2" runat="server"
                         UpdateMode="Conditional">
                         <ContentTemplate>
                              <asp:Label ID="Label2" runat="server" ForeColor="red" />
                         </ContentTemplate>
                         <Triggers>
                              <asp:AsyncPostBackTrigger ControlID="Button1" EventName="Click" />
                         </Triggers>
                    </asp:UpdatePanel>
               </div>
          </form>
</body>
</html>

Code:

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

protected void Button2_Click(object sender, EventArgs e)
{
    Label1.Text = DateTime.Now.ToLongTimeString();
}

I'll post the web.config if needed, but again, they are exactly the same (copy pasted). ANy help would be appreciated.


Try taking the buttons out of the first update panel. Also, try "ChildrenAsTriggers=true" inside the updatepanel tag.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号