更新面板不更新内容

sur*_*van 5 asp.net ajax updatepanel

我从一段时间开始尝试这个,但我无法绕过它.以下是aspx页面显示的代码:

<!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>
Run Code Online (Sandbox Code Playgroud)

以下是button1单击事件的代码:

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
Run Code Online (Sandbox Code Playgroud)

你能告诉我我错过了什么吗?

小智 2

在下拉列表中将自动回发设置为 true。

真正的意思是:每次下拉列表中的值发生更改时,都会向服务器进行回发。

但请听听蒂姆·施梅尔特的回答。如果下拉列表不会改变,最好将其放在更新面板之外,并且更新面板必须由下拉列表异步触发(如果您没有为更新面板设置触发器,则每次回发都会更新您的更新面板)。如果下拉列表的内容发生变化,请将其放入更新面板中。

但就像我说的,我很长一段时间都没有使用它,最好仔细检查我所说的有关该主题的所有内容。=p

PS:Microsoft 更新面板很容易开发,但会使您的网站速度非常慢。尝试了解 aspnet webservices 和 jQuery。