我有default.aspx使用的masterpage,在母版页中我有一个名为DefaultMenuContent的控件,这个控件有一个带有autopostback的下拉列表,即使我在控件的加载事件中使用Is Not PostBack,问题也会失去选择,
每次都是新的加载,而不是在这种情况下回发! 如何坚持下拉列表选择?
在主人:
<asp:ContentPlaceHolder ID="MenuContentPlaceHolder" runat="server">
<art:DefaultArabicMenu ID="DefaultMenuContent" runat="server" />
</asp:ContentPlaceHolder>
在Default.aspx中
Protected Sub ddl_Srv_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddl_Srv.Load
If Not Page.IsPostBack Then
Bind_List()
End If
End Sub
答案 0 :(得分:1)
假设您只想存储当前用户会话的选择,您可以将选择保存在会话变量中。
Protected Sub dropdownlist1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles dropdownlist1.SelectedIndexChanged
' save selection
Session("ddl1_selection") = dropdownlist1.SelectedValue
' do rest of logic
End Sub
在页面加载事件中检查变量并进行选择
Protected Sub ddl_Srv_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not Page.IsPostBack Then
Bind_List()
If Session("ddl1_selection") IsNot Nothing Then
dropdownlist1.SelectedValue = Session("ddl1_selection")
End If
End If
End Sub