473,320 Members | 1,612 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

passing values from programmatically created controls

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
Apr 5 '06 #1
0 1155

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: domeceo | last post by:
can anyone tell me why I cannot pass values in a setTimeout function whenever I use this function it says "menu is undefined" after th alert. function imgOff(menu, num) { if (document.images) {...
7
by: Ken Allen | last post by:
I have a .net client/server application using remoting, and I cannot get the custom exception class to pass from the server to the client. The custom exception is derived from ApplicationException...
7
by: Wade Wegner | last post by:
Hello, I have been desperately trying to programmatically authenticate a windows user, create their credentials, and then redirect them to a different server while passing the credentials at the...
3
by: Jen | last post by:
Hi I have created some controls (HtmlInputText, HtmlGenericControl, TextBox) dynamically. But I have problem getting the values from these controls to save them. Is there a way to do that? ...
9
by: james.e.coleman | last post by:
Hello, I have created a custom dropdownlist that is used multiple times within a single page. When trying to set the values of the controls with the page in which they are being used, they all...
11
by: John Pass | last post by:
Hi, In the attached example, I do understand that the references are not changed if an array is passed by Val. What I do not understand is the result of line 99 (If one can find this by line...
4
by: Bob | last post by:
Hi, I'm working with VWD and i defined programmatically a button (in code-behind) with an ID. So I expect to see beside "Page Events" and "Form1" my button "b1" in order to use the Click event....
8
by: hunanwarrior | last post by:
I added textbox controls to a form when user selects amount to create from a combobox as follows: 'Load up the combobox Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As...
4
by: Siv | last post by:
Hi, I have an application that reads information from a database and depending on that information creates controls on a form. Depending on where the user is at in a process there may be one item...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.