Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8254447
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T01:11:29+00:00 2026-06-08T01:11:29+00:00

I’m new to asp.net (after programming for years in classic asp). I’m trying to

  • 0

I’m new to asp.net (after programming for years in classic asp). I’m trying to build a page which adds something to a string.

My code is following:

default.aspx

<body>
<form id="form1" runat="server">
<div>
<p><asp:textbox id="tb" runat="server"></asp:textbox></p>
<asp:Panel ID="tbPanel" runat="server"></asp:Panel>
</div>
</form>
</body>

Code behind:

Partial Class demo_Default
Inherits System.Web.UI.Page


Public Property gesStr As String

Set(value As String)

ViewState("gesStr") = value

End Set

Get

Dim o As Object = ViewState("gesStr")

If o Is Nothing Then

Return ""

Else

Return o

End If

End Get

End Property


Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
Dim anzeigeStr As String = ""
If Page.IsPostBack Then
Else
gesStr = "1;"
End If
tb.Text = gesStr


Dim iButton As New Button
iButton.Text = "add"
iButton.CommandArgument = "1;"
AddHandler iButton.Click, AddressOf add
tbPanel.Controls.Add(iButton)


Me.anzeige()


End Sub


Private Sub add(ByVal sender As Object, ByVal e As EventArgs)
Dim myButton As Button = DirectCast(sender, Button)
Dim addString As String = myButton.CommandArgument
gesStr += addString
End Sub


Private Sub anzeige()
Dim gesArray As Array = Split(gesStr, ";")
For xLauf As Integer = 0 To UBound(gesArray) - 1
Dim anzLabel As New Label
anzLabel.Text = "<p>" & gesArray(xLauf) & "</p>"
tbPanel.Controls.Add(anzLabel)
Next




End Sub

End Class

The problem:

Pressing the button will cause a postBack, but the result of adding won’t appear until the button is pressed a second time. The desired result is that the sub displays the correct array within the loop after the first time pressing the button.

Thank you so much for any help!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T01:11:31+00:00Added an answer on June 8, 2026 at 1:11 am

    You need to call the function anzeige() and bind gesStr value to the textbox control each time the button is click. See the code below:

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    
            If Page.IsPostBack Then
            Else
                gesStr = "1;"
            End If
            tb.Text = gesStr
            Dim iButton As New Button
            iButton.Text = "add"
            iButton.CommandArgument = "1;"
            iButton.CommandName = "1;"
            AddHandler iButton.Click, AddressOf add
            tbPanel.Controls.Add(iButton)
    
        End Sub
    
        Private Sub add(ByVal sender As Object, ByVal e As EventArgs)
    
            Dim myButton As Button = DirectCast(sender, Button)
            Dim addString As String = myButton.CommandArgument
            gesStr += addString
    
            anzeige()
        End Sub
    
    
        Private Sub anzeige()
            Dim gesArray As Array = Split(gesStr, ";")
            For xLauf As Integer = 0 To UBound(gesArray) - 1
                Dim anzLabel As New Label
                anzLabel.Text = "<p>" & gesArray(xLauf) & "</p>"
                tbPanel.Controls.Add(anzLabel)
            Next
    
            'Bind gesStr value to the textbox control
            tb.Text = gesStr
    
        End Sub
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
I would like to count the length of a string with PHP. The string
I used javascript for loading a picture on my website depending on which small

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.