开发者

Dropdownlist Autopost back issue: Remembering the selection

I would like to change the dropdown list and whenever I make some changes it should auto post back and triggers a selectedindexchanged event for drop down list. I am having problem where it does auto post back but doesnt remember what I selected, it refreshes my page and item that i selected gets 开发者_Python百科lost. I would like to do this without AJAX call. But, if AJAX is the only option, I am open to it.

<asp:DropDownList ID="ddlProjectEditor" CssClass="ddlProjectEditor" Autopostback="true"  runat="server" >
    </asp:DropDownList>

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
  If Not Page.IsPostBack Then
        Dim F As facility = utilities.lookForFacility
        'Option to add Project information in editor

        _config = CType(System.Configuration.ConfigurationManager.GetSection("editorConfigGroup/general"), f896EditorConfig.Config.General)


        If F IsNot Nothing Then
            Dim _facilityID As String = F.FacilityID
            Dim count As Integer = 0
            Dim facility As facility = FacilityManager.getFacility(_facilityID, True)
            Me.ddlProjectEditor.Items.Insert(count, New ListItem(F.CompanyName, F.FacilityID))

            'Me.ddlProjectEditor.SelectedIndex = 0
            'Me.ddlProjectEditor.ClearSelection()


            For Each memberFID As String In (From Rel In facility.Relationships Where Rel.numberType = "hllTeam" Or Rel.numberType = "hllOffice" Select Rel.storeNumber)
                count = count + 1
                Dim CompanyName = FacilityManager.getFacility(memberFID, True).CompanyName
                Me.ddlProjectEditor.Items.Insert(count, New ListItem(CompanyName, memberFID))
            Next
        End If
    End If


End Sub

Protected Sub ddlProjectEditor_SelectedIndexChanged2(ByVal sender As Object, ByVal e As EventArgs) Handles ddlProjectEditor.SelectedIndexChanged
        Dim selectedFacilityID = ddlProjectEditor.SelectedItem.Value 
'This event doesn't get triggered.

    End Sub


You have to check the page directive in the web.configfile and see if EnableViewState="false". If that is the case then change it to EnableViewState="true"


Change ddlProjectEditor_SelectedIndexChanged2 to Public and add OnSelectedIndexChanged="ddlProjectEditor_SelectedIndexChanged2" to the drop down list markup.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜