停止DropDownList在Asp.net webforms中刷新页面

时间:2011-07-01 01:14:38

标签: asp.net drop-down-menu autopostback

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

<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事件,但页面会刷新。我可以阻止它发生吗?

3 个答案:

答案 0 :(得分:2)

从标记中省略AutoPostBack属性。

AutoPostBack获取或设置一个值,该值指示在DropDownList中更改所选索引时是否发生自动回发服务器。此DropDownList.AutoPostBack的默认值为 false

如果您需要更新网页数据的一部分,可以使用Partial Page Updates with ASP.NET AJAX

答案 1 :(得分:1)

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

答案 2 :(得分:1)

解决方案:

在您的情况下,您需要使用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>

<强>问候
阿里穆罕默德

相关问题