加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

asp.net – 更新面板不更新内容

发布时间:2020-12-16 06:59:05 所属栏目:asp.Net 来源:网络整理
导读:我从一段时间开始尝试这个,但我无法绕过它.以下是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="
我从一段时间开始尝试这个,但我无法绕过它.以下是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>

以下是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

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

解决方法

在下拉列表中将autopostback设置为true.

真实的意思是:每次下拉列表中的值发生变化时,都会发生对服务器的回发.

但请听Tim Schmelter的回答.如果下拉列表不会更改,最好将其放在更新面板之外,并且必须通过下拉菜单异步触发更新面板(如果您没有为更新面板设置触发器,则每次回发都会更新您的UpdatePanel中).如果下拉列表的内容发生更改,请将其放在updatepanel中.

但就像我说的那样,我很长一段时间没有使用它,最好仔细检查一下我对这个主题所说的一切. = p

PS:Microsoft Update面板易于开发,但会使您的网站速度变慢.尝试了解aspnet webservices和jQuery.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读