This is a migrated thread and some comments may be shown as answers.

Reading dynamically added data on postback

1 Answer 91 Views
ListBox
This is a migrated thread and some comments may be shown as answers.
judo
Top achievements
Rank 1
judo asked on 07 Sep 2009, 12:13 PM
I have a Listbox on my page which I add RadListBoxitems to on page.load , however when I try read these items from a button.click event they disappear. I can add the items back on page.load but this wont solve the problem as the items the user selected are lost. I guess this is more of an ASP.NET issue but I am stumped as to how I should solve it (I enabled viewstate and presistclientchanges but with no luck).

aspx code:
 <telerik:RadScriptManager ID="RadScriptManager1" runat="server"
        </telerik:RadScriptManager> 
        <telerik:RadListBox ID="RadListBox1" runat="server" Style="left: 0px; top: 0px" EnableViewState="true" 
            ButtonSettings-ShowTransferAll="False" CheckBoxes="True"
            <ButtonSettings ShowTransferAll="False" /> 
        </telerik:RadListBox> 
        <asp:Button ID="submitBtn" runat="server" Text="Submit" /> 

code behind:
  Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load 
        If Not Page.IsPostBack Then 
            populateUserListing() 
 
        End If 
    End Sub 
 
    Protected Sub submitBtn_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles submitBtn.Click 
          
        For i As Integer = 0 To RadListBox1.Items.Count - 1 
            If RadListBox1.Items(i).Checked Then 
                'do actions here 
            End If 
        Next 
          
  
    End Sub 
 
 
    Sub populateUserListing() 
  
        For i As Integer = 0 To item.Count - 1 
            Dim dummyListItem As New RadListBoxItem("xxx", "xxx") 
            RadListBox1.Items.Add(dummyListItem) 
  
        Next 
 
    End Sub 

Thanks



1 Answer, 1 is accepted

Sort by
0
Genady Sergeev
Telerik team
answered on 10 Sep 2009, 02:03 PM
Hi judo,

I have created sample project using the very code you have provided. As far as I can see, the items are correctly preserved over the postbacks. In the submit button click handler I am able to access all of the previously added files. You can find my sample project as an attachment. Am I missing something?

Regards,
Genady Sergeev
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Tags
ListBox
Asked by
judo
Top achievements
Rank 1
Answers by
Genady Sergeev
Telerik team
Share this question
or