passing values from programmatically created controls

T

TB

Hi All:

I have this page where a rows / cells are programmatically added to to table
by pushing a button.

The rows contain a textbox and a associated button. What I want to is to be
able to add the content of any textbox to a global variable (and a related
session variable) when pushing the associate button.

However whenever I push the button(s) apparently the session variable is not
correctly updated and therefore nothing is updated. I have a feeling that it
has something to do with the "handles" argument in the click event of the
programmatically created buttons and / or the dynamically assigned textbox
and button names, but I am not sure.

Below is simplied version of the page

Content of sessiontest.aspx:

<%@ Page Language="vb" AutoEventWireup="false"
Codebehind="sessiontest.aspx.vb" Inherits="testsite.sessiontest"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>sessiontest</title>
<meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" content="Visual Basic .NET 7.1">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema"
content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body>
<form id="Form1" method="post" runat="server">
<asp:placeholder id="plhtable" Runat="server"></asp:placeholder><br>

<asp:Button ID="btnAddrow" Text="Add Row" Runat="server" />
</form>
</body>
</HTML>

Contant of sessiontest.aspx.vb

Public Class sessiontest
Inherits System.Web.UI.Page

Dim td As TableCell
Dim tb As Table
Dim tr As TableRow
Dim btntest As Button
Dim txbtest As TextBox
DIM strResult as string ' This is where I want to store everything

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
If Not IsPostBack Then
tb = New Table
addrows()

Else
tb = Session("table")
strResult = Session("strResult")
End If
plhtable.Controls.Add(tb)
End Sub
Sub page_prerender(ByVal sender As Object, ByVal e As EventArgs) Handles
MyBase.PreRender
Session("Table") = tb
Session("strResult") = strResult
End Sub
Sub addrows()

tr = New TableRow
txbtest = New TextBox

td = New TableCell
td.Text = "Enter text:"
tr.Cells.Add(td)

td = New TableCell
txbtest.ID = "txbNumber" & tb.Rows.Count()
td.Controls.Add(txbtest)
tr.Cells.Add(td)

td = New TableCell
btntest = New Button
AddHandler btntest.Click, AddressOf valuefromtxb_click
btntest.ID = "btnNumber" & tb.Rows.Count()
btntest.Text = "Button #" & tb.Rows.Count()

td.Controls.Add(btntest)
tr.Cells.Add(td)

tb.Rows.Add(tr)
End Sub

Private Sub fromtxb_click(ByVal sender As System.Object, ByVal e As
System.EventArgs)
counter = counter + 1
strResult = strResult % & txbtest.Text

End Sub
Private Sub btnAddrow_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnAddrow.Click
addrows()
End Sub
End Class


Any suggestions will be higly appreciated.

Thanks.

TB
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top