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
laceholder id="plhtable" Runat="server"></asp
laceholder><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 valuefromtxb_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
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


<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 valuefromtxb_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