473,385 Members | 1,727 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,385 software developers and data experts.

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 1776

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

Similar topics

1
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
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
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
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
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
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
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
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
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
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
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...

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.