473,399 Members | 4,254 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,399 software developers and data experts.

How do I access a control from a class not other than WebForm1?

I created a web form and dropped a table in there called resultsTable. This
also resulted in the following being added to the Webform1 class:
public System.Web.UI.WebControls.Table resultsTable;

I can easily add rows and columns via C# programming from the WebForm1
class. However I cannot figure out how I can access this control outside of
this class.

For example, I have a different class called TestResult. As I create
TestResult classes from the Page_Load event, I want the constructor of
TestResult to add rows and columns to the resultsTable. However I can't
figure out how I can access the resultsTable from my TestResult constructor.

For example:

private void Page_Load(object sender, System.EventArgs e)
{
// Generate rows and cells.
TestResult[] TestResults = new TestResult[3];
TestResults[0] = new TestResult("Mike Brown", "Pass");
TestResults[1] = new TestResult("Jill Smith", "Did not attend");
...

So then in my TestResult constructor, as I receive the name and status (i.e.
Mike Brown, Pass) I want to add a row to the table for each person and set
the cells to these values, among other things that the constructor is doing.
I imagine I can pass a reference to the testResult table but that seems a
bit messy. Is there a better way? How can I talk to the testResults table
to add these rows/columns from a class other than the class testResults
table is defined in?

Thank you.

Nov 18 '05 #1
2 1244
The easiest, IMO, would be to pass in the table object, by reference, to the
class you are using to add rows.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

************************************************
Think Outside the Box!
************************************************
"Richard Dixson" <re***@here.com> wrote in message
news:vo********************@comcast.com...
I created a web form and dropped a table in there called resultsTable. This also resulted in the following being added to the Webform1 class:
public System.Web.UI.WebControls.Table resultsTable;

I can easily add rows and columns via C# programming from the WebForm1
class. However I cannot figure out how I can access this control outside of this class.

For example, I have a different class called TestResult. As I create
TestResult classes from the Page_Load event, I want the constructor of
TestResult to add rows and columns to the resultsTable. However I can't
figure out how I can access the resultsTable from my TestResult constructor.
For example:

private void Page_Load(object sender, System.EventArgs e)
{
// Generate rows and cells.
TestResult[] TestResults = new TestResult[3];
TestResults[0] = new TestResult("Mike Brown", "Pass");
TestResults[1] = new TestResult("Jill Smith", "Did not attend");
...

So then in my TestResult constructor, as I receive the name and status (i.e. Mike Brown, Pass) I want to add a row to the table for each person and set
the cells to these values, among other things that the constructor is doing. I imagine I can pass a reference to the testResult table but that seems a
bit messy. Is there a better way? How can I talk to the testResults table to add these rows/columns from a class other than the class testResults
table is defined in?

Thank you.

Nov 18 '05 #2
I was thinking along those lines - just seems kind of messy. For example I
have:

TestResults[0] = new TestResult("Bill Brady", "Pass", resultsTable);
TestResults[1] = new TestResult("Jill Smith", "Did not attend",
resultsTable);

Just doesn't seem very elegant/programatically correct.

Isn't there some way that I could have the TestResult class call a method or
property in Webform to get a reference to the resultsTable. The more I
think about it that should be doable. For example if I add a getter to the
Webform class that returns a reference to the resultsTable, then I can use
that getter from my TestResult class to obtain a copy, right?

"Cowboy" <No************@comcast.netNoSpamM> wrote in message
news:eD**************@TK2MSFTNGP10.phx.gbl...
The easiest, IMO, would be to pass in the table object, by reference, to the class you are using to add rows.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

************************************************
Think Outside the Box!
************************************************
"Richard Dixson" <re***@here.com> wrote in message
news:vo********************@comcast.com...
I created a web form and dropped a table in there called resultsTable. This
also resulted in the following being added to the Webform1 class:
public System.Web.UI.WebControls.Table resultsTable;

I can easily add rows and columns via C# programming from the WebForm1
class. However I cannot figure out how I can access this control outside of
this class.

For example, I have a different class called TestResult. As I create
TestResult classes from the Page_Load event, I want the constructor of
TestResult to add rows and columns to the resultsTable. However I can't
figure out how I can access the resultsTable from my TestResult

constructor.

For example:

private void Page_Load(object sender, System.EventArgs e)
{
// Generate rows and cells.
TestResult[] TestResults = new TestResult[3];
TestResults[0] = new TestResult("Mike Brown", "Pass");
TestResults[1] = new TestResult("Jill Smith", "Did not attend");
...

So then in my TestResult constructor, as I receive the name and status

(i.e.
Mike Brown, Pass) I want to add a row to the table for each person and

set the cells to these values, among other things that the constructor is

doing.
I imagine I can pass a reference to the testResult table but that seems a bit messy. Is there a better way? How can I talk to the testResults

table
to add these rows/columns from a class other than the class testResults
table is defined in?

Thank you.


Nov 18 '05 #3

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

Similar topics

0
by: Amir Eshterayeh | last post by:
Dear Friends Hope things goes well to you. I have this problem. Would you please give me your solution? I want to change a property that I define on my user control in my web form that contains...
6
by: Christopher Young | last post by:
I have several user controls on a page and I am trying to get information out of them. The postback is being caused on the aspx page and not in the user control. I have tried using a property but...
29
by: Patrick | last post by:
I have the following code, which regardless which works fine and logs to the EventViewer regardless of whether <processModel/> section of machine.config is set to username="SYSTEM" or "machine" ...
1
by: William Parker | last post by:
I have a web control I made called header.ascx. It has its own properties and methods I defined. But I cannot figure out how to access this control from my code behind page. I can create the...
3
by: qwerty | last post by:
I have two User controls in a page. Them ID-propertys are example UC1 and UC2. In code behind file they are declared: Public UC1 As UC1 Public UC1 As UC1 From the page I can call them with...
9
by: John Smith | last post by:
Hi, I have this problem. I have a page class in code behind called "WebForm1" and I have another class called "Class1". Now in Class1 I am creating ImageButton and I am adding event handler...
3
by: Jeff User | last post by:
Hello I am using C#, .net1.1 Vis Studio 2003 I am using homeBase.aspx.cs page as a base for several other aspx/aspx.cs web pages. The base page handles some operations that are common to all...
1
by: Paul | last post by:
Hi I have a simple C# web application with only 1 form and about 20 controls on it. I have a large section that enables all of the controls and makes them visible based on screen inputs. I moved...
1
by: =?Utf-8?B?Tmltcm9kIFJvdG5lcg==?= | last post by:
Hi, I built a web control wich has text box and public property that set or get the text value of that text box. when i try to access that property i got error: "Object reference not set to an...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
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
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...

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.