page which adds something to a string

mhanning

New member
Joined
Jul 16, 2012
Messages
2
Programming Experience
1-3
Hey there,

as a newbie to asp.net (after programming for years in classic asp) i'm trying to build a page which adds something to a string - I apologize for my rusty English, too...

My code is following:

default.aspx

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default6.aspx.vb" Inherits="demo_Default" %>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">


<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<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>
</html>

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... I have trying everything I know - so please, I you have an idea what to do, give me a hind. Thank you so much :)
 
The desired result is that the sub displays the correct array within the loop after the first time pressing the button...
 
Back
Top