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 va开发者_Go百科lue 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.
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
The SelectedValue is read from the ViewState on postback. But the ViewState is no longer available on the next page. Why don't you save the SelectedValue in Session so you can refer to it on the next page?
In this case you can persist the value in viewstate before redirecting to another page. So from the next page you call just like:
Public ReadOnly Property CustID() As String
Get
Return viewstate("myCustID")
End Get
End Property
I hope it will work.
精彩评论