1

我有一个正常的下拉列表:

<asp:DropDownList ID="kindofser" runat="server" AutoPostBack="True" 
        Height="21px" Width="166px" 
        onselectedindexchanged="kindofser_SelectedIndexChanged">
        <asp:ListItem>שרתי משחק</asp:ListItem>
        <asp:ListItem Value="1">rgrgr</asp:ListItem>
        <asp:ListItem Value="2">rgreger</asp:ListItem>

    </asp:DropDownList>

每次我更改选项时,都会发生 SelectedIndexChanged 事件,但页面会刷新。我能阻止它发生吗?

4

3 回答 3

2

AutoPostBack从标记中省略属性。

AutoPostBack获取或设置一个值,该值指示当所选索引在DropDownList. DropDownList.AutoPostBack默认值为false

如果您需要更新页面数据的一部分,您可以使用带有 ASP.NET AJAX 的部分页面更新

于 2011-07-01T01:17:59.900 回答
2

解决方案:

在您的情况下,您需要使用 updatepanel,因为您正在使用“onselectedindexchanged”事件。所以这里的代码

<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>

<asp:DropDownList ID="kindofser" runat="server" AutoPostBack="True" 
        Height="21px" Width="166px" 
        onselectedindexchanged="kindofser_SelectedIndexChanged">
        <asp:ListItem>שרתי משחק</asp:ListItem>
        <asp:ListItem Value="1">rgrgr</asp:ListItem>
        <asp:ListItem Value="2">rgreger</asp:ListItem>
</asp:DropDownList>


</ContentTemplate>  
</asp:UpdatePanel>

问候
阿里·穆罕默德

于 2013-12-03T11:54:46.013 回答
1

设置AutoPostBack="False"而不是 true。

于 2011-07-01T01:16:28.050 回答