473,508 Members | 2,343 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Access Programmetically created controls

ok, here is the situation, I am trying to construct a table with
several ASP.net 2.0 controls in it during execution time in an VB.net
enviroment. For starters, I have a textbox and a linkbutton per row of
the table. I have easily constructed the table, but on the postback, I
am unable to access the controls... Here is an example of the code:

''' <summary>Page Load</summary>
''' <remarks>
''' <para>Ensure that the querystring has a client ID or else it
resends it to <see cref="Payment"/>.</para>
''' </remarks>
Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load
'If Request.QueryString(Navigation.CLIENT) Is Nothing Or
Val(Request.QueryString(Navigation.CLIENT)) = 0 Then
' Dim Nav As New Navigation(Navigation.Webpages.WebPayment)
' Response.Redirect(Nav.toString)
'End If
hdnClientID.Value = 44
'Val(Request.QueryString(Navigation.CLIENT))
If Not Page.IsPostBack Then
lblClientName.Text = New
DataAccessLayer.Client(Val(hdnClientID.Value)).Cli ent_Name
End If
ConfigureTable()
End Sub

''' <summary>Redirect to Client Information</summary>
''' <remarks>
''' <para>Redirects to <see cref="Clients"/></para>
''' </remarks>
Protected Sub lnkClient_Click(ByVal sender As System.Object, ByVal
e As System.EventArgs) Handles lnkClient.Click
Dim Nav As New Navigation(Navigation.Webpages.WebClient)
Nav.ClientID = Val(hdnClientID.Value)
Response.Redirect(Nav.toString)
End Sub

''' <summary>Create Invoice Table</summary>
''' <remarks>
''' <para>construct an amount of rows to be determined by the
number of invoices the client has.</para>
''' </remarks>
Protected Sub ConfigureTable()
Dim Data As IList(Of DataAccessLayer.Invoices) =
DataAccessLayer.Invoices.getUnPaidInvoicesByClient ID(Val(hdnClientID.Value))

tblInvoices.Rows.Add(createHeaderRow)

For Each Record As DataAccessLayer.Invoices In Data
Dim Rows As New TableRow
For Counter As Integer = 0 To 6
Rows.Cells.Add(createCell(Counter, Record))
Next
Rows.EnableViewState = True
tblInvoices.Rows.Add(Rows)
Next
End Sub

''' <summary>On Transfer Button Click</summary>
''' <remarks>
''' <para>When the user clicks the button to transfer the
information to the other columns, this function grabs the row that was
selected, and then takes it and applies it to the other labels.</para>
''' </remarks>
Protected Sub TransferButton(ByVal sender As System.Object, ByVal e
As System.EventArgs)
Dim myButton As LinkButton = sender
Dim txt As New TextBox
txt.id = "txtApply" & myButton.CommandName
MessageBox(txt.Text)
End Sub

''' <summary>Construct the individual cells</summary>
''' <remarks>
''' <para>Determine what cell is being created using the CellID
number and then return the constructed cell with the controls already
connected.</para>
''' </remarks>
Protected Function createCell(ByVal CellID As Integer, ByRef data
As DataAccessLayer.Invoices) As TableCell
Const CELL_WIDTH As Integer = 13
Dim Cell As New TableCell

Select Case CellID
Case 0
Dim lbl As New Label
lbl.Text = data.Inv_Number
lbl.BorderStyle = BorderStyle.Inset
lbl.EnableViewState = True

Cell.Width = Unit.Percentage(CELL_WIDTH)
Cell.Controls.Add(lbl)
Case 1
Dim lbl As New Label
lbl.Text = data.Inv_Date
lbl.BorderStyle = BorderStyle.Inset
lbl.EnableViewState = True
Cell.Width = CELL_WIDTH
Cell.Controls.Add(lbl)
Case 2
Dim lbl As New Label
lbl.Text = data.Inv_Total - data.Inv_AmountPaid
lbl.BorderStyle = BorderStyle.Inset
lbl.EnableViewState = True
Cell.Width = Unit.Percentage(CELL_WIDTH)
Cell.Controls.Add(lbl)
Case 3
Dim txt As New TextBox
txt.EnableViewState = True
txt.ID = "txtApply" & data.Inv_ID
Cell.Width = Unit.Percentage(CELL_WIDTH)
Cell.Controls.Add(txt)
Case 4
Cell.Width = Unit.Percentage(CELL_WIDTH)
Cell.Text = " "
Case 5
Dim Link As New LinkButton
AddHandler Link.Click, AddressOf TransferButton
Link.Text = "X"
Link.CommandName = data.Inv_ID
Link.EnableViewState = True
Cell.EnableViewState = True
Cell.Controls.Add(Link)
Case 6
Dim lbl As New Label
lbl.Text = data.Inv_Number
lbl.BorderStyle = BorderStyle.Inset
lbl.EnableViewState = True
Cell.Width = Unit.Percentage(CELL_WIDTH)
Cell.Controls.Add(lbl)
End Select

Return Cell
End Function

''' <summary>Create Header Row for the dynamic table</summary>
''' <remarks></remarks>
Protected Function createHeaderRow() As TableHeaderRow
Dim DataRow As New TableHeaderRow
Dim DataCell As TableHeaderCell

DataCell = New TableHeaderCell
DataCell.Text = "Invoice Number"
DataRow.Cells.Add(DataCell)
DataCell = New TableHeaderCell
DataCell.Text = "Date"
DataRow.Cells.Add(DataCell)
DataCell = New TableHeaderCell
DataCell.Text = "Balance"
DataRow.Cells.Add(DataCell)
DataCell = New TableHeaderCell
DataCell.Text = "Discount"
DataRow.Cells.Add(DataCell)
DataCell = New TableHeaderCell
DataCell.Text = "Cash Applied"
DataRow.Cells.Add(DataCell)
DataCell = New TableHeaderCell
DataRow.Cells.Add(DataCell)
DataCell = New TableHeaderCell
DataCell.Text = "Total Applied"
DataRow.Cells.Add(DataCell)

Return DataRow
End Function
For simplicity, Messagebox sends up a javascript alert with what ever
is passed to it.

Please Help, I have tried, page.findcontrol(), findcontrol(), creating
a new textbox with the same id, tblInvoices.findcontrol(),
cell.findcontrol() and all sorts of other idiotic steps to access this
information. I know the answer is something simple, but it simply
eludes me.

Thank You in advance.
Eric Forkrud

Sep 19 '06 #1
0 1785

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

Similar topics

1
1290
by: Conrad Chan | last post by:
I am trying to build some utilities for our internal development. Is there any way I can programmetically find out the original source file for a given class? Say I am inspecting a CLR type in...
3
2446
by: hi | last post by:
Hi, Is there an IRC channel for help with access? I've created a form with some fields from several tables. When I go to "Form View" the fields I created with the wizard along with several...
5
5515
by: Andrei Pociu | last post by:
Inside a method some controls are created at runtime. I added an event handler to one of these controls: tracker.Scroll += new System.EventHandler(this.tracker_Scroll); So in the event handler...
7
6965
by: Lau Lei Cheong | last post by:
Hello, I'm using javascript's insertAdjacentHtml() to insert images to the webform at runtime. This runs fine(image successfully displayed at the browser) but when I tried to access the...
2
1668
by: c676228 | last post by:
Hi, I created a group of user controls in an aspx form. which is as follow: <body> <form id="Form1" method="post" runat="server"> <SUBWAY:PEOPLEINFO id="Peopleinfo0" runat="server"...
52
9914
by: Neil | last post by:
We are running an Access 2000 MDB with a SQL 7 back end. Our network guy is upgrading to Windows Server 2003 and wants to upgrade Office and SQL Server at the same time. We're moving to SQL Server...
0
427
by: comp974 | last post by:
ok, here is the situation, I am trying to construct a table with several ASP.net 2.0 controls in it during execution time in an VB.net enviroment. For starters, I have a textbox and a linkbutton...
7
2281
by: Andy B | last post by:
I have a class I am creating for data access. I need to access controls from inside the class that are on a particular page. How do I do this? or is creating an instance of the page class and using...
6
2401
by: Wesley Peace | last post by:
I hate to cross post, but I've gotten no answer yet on a problem I'm having with visual studio 2008. I've created a series of forms with controls to access a Access database tables. The...
0
7225
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7123
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7324
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7382
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7495
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
4707
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3193
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3181
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1556
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.