Click here to Skip to main content
15,918,706 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi, This is lakshmana rao, i have a text box in updatepanel like this
ASP.NET
<asp:ScriptManager ID="ScriptManager1" runat="server">
     </asp:ScriptManager>     
     <asp:UpdateProgress ID="UpdateProgress1" AssociatedUpdatePanelID="UpdatePanel1" runat="server">
        <ProgressTemplate>
        </ProgressTemplate>
     </asp:UpdateProgress>
     <asp:UpdatePanel ID="UpdatePanel1" UpdateMode="Conditional" runat="server">
            <Triggers> 
            <asp:AsyncPostBackTrigger ControlID="Button1" EventName="Click" />               
            </Triggers>
        <ContentTemplate>
        <asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />
        <asp:Timer ID="Timer1" runat="server" Interval="10" EnableViewState="false" Enabled="False">
        </asp:Timer>
        <asp:TextBox ID="TextBox1" runat="server" AutoPostBack="True"></asp:TextBox>
        </ContentTemplate>
        </asp:UpdatePanel>


And The VB code is
VB
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
        For intindex As Integer = 1 To 10
            TextBox1.Text = intindex.ToString
            UpdatePanel1.Update()
        Next
    End Sub


when i run this code in for loop the loop values are assigned to textbox text property but it can't displayed in the textboxes, only last record is displayed in the textbox. can any one suggest me how can i get simultaneously with for loop my textbox values are changed.
Posted
Comments
[no name] 31-Aug-12 7:02am    
"TextBox1.Text = intindex.ToString"... what ever it is that you eventually want to do, this is assigning the text to the textbox not adding to it which seems to be what your question is. So when your loop is done, all you are going to see is the last value. "how can i get simultaneously with for loop my textbox" makes no sense at all.

Try:
VB
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
    Dim sb As New StringBuilder
    For intindex As Integer = 1 To 10
        sb.AppendFormat("{0} ", intindex)
    Next
    TextBox1.Text = sb.ToString()
    UpdatePanel1.Update()
End Sub
 
Share this answer
 
v2
Comments
lakshmanarao.vemula 1-Sep-12 1:09am    
thx, its working but i want only one value at a time. i don't want append the values.i want change text every loop.
OriginalGriff 1-Sep-12 3:14am    
You can't - without removing the loop!
If you want the value to change each time you press the button, then that is just a case of removing the loop and doing one "iteration" manually each time you get the Click event. But once you get the click event, nothing else will happen until the event handler ends - on screen updates, no nothing. So if you loop in the handler, only the final result of the loop will ever be shown.

It's like dealing cards from a pack - if you deal off five cards face up into a pile on the table, when you have finished you can only see the last card you dealt, no matter how many times you deal out five cards.
lakshmanarao.vemula 1-Sep-12 5:12am    
is there any other way
OriginalGriff 1-Sep-12 5:17am    
No :laugh:
Think of a text box as the pile of cards I mentioned. It can only show the one card at a time. The only way to make it change it's text would be as a result of an event - the button click event, or you could set up a timer. But you can't just say "display this, no this, no this", and expect the user to be able to see them all! :laugh:
Simple:
VB
TextBox1.Text &= intindex.ToString
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900