开发者

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 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.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜