Search code examples
asp.netwebformslistboxcross-page-posting

ASP.NET webforms listbox - cross-page posting


I'm new to ASP.NET, and I'm having a problem getting a listbox to return the proper data when posting to another page. I have gotten dropdownlists and radio buttons to work. For instance, for dropdownlists, I simply did this:

Public ReadOnly Property SiteID() As String
    Get
        Return ddlSites.SelectedValue
    End Get

Then, on the next page, I successfully returned the value using PreviousPage.SiteID. However, when I try this for a listbox:

Public ReadOnly Property CustID() As String
    Get
        Return lstLoggedInCustomers.SelectedValue.ToString
    End Get
End Property

then call it using PreviousPage, I get an empty string, as SelectedIndex is always returning -1, even though I select an item in the listbox.


Solution

  • I had a similar situation. I used user252340's approach and store the value:

    Session["MemberName"] = memberName;
    

    and then in the PageLoad of the other page get the value:

     MemberName.Value = Session["MemberName"].ToString();
    

    Hope this helps