ASP.NET webforms listbox - interstitial wiring

I'm new to ASP.NET, and I had a problem getting a list to return the correct data when sending to another page. I have dropdownlists and switches to work. For example, for dropdownlists I just 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 the PreviousPage.SiteID method. However, when I try to do this for a list:

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, since SelectedIndex always returns -1, although I select an item in the list.

+3
source share
3 answers

I had a similar situation. I used the user252340 approach and saved the value:

Session["MemberName"] = memberName;

PageLoad :

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

,

+1

ViewState . ViewState . SelectedValue , ?

+1

In this case, you can save the value in viewstate before redirecting to another page. So, from the next page you call like this:

Public ReadOnly Property CustID() As String
    Get
        Return viewstate("myCustID") 
    End Get
End Property

I hope this works.

0
source

Source: https://habr.com/ru/post/1787150/


All Articles