473,586 Members | 2,817 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Simple OO Question for .NET

Hi,
If I want to dynamically build an asp:table in a class file and return
it to the caller as an object ie:

public Table TableGenerator( ){

public Table myTable = new Table();
....
....
return myTable;
}

My question is this, how do I call this method and display the
resulting table in the presentation layer. I'm sure there is more than
one way to accomplish this.

Thanks,
Jon

Apr 25 '06 #1
7 1066
To call the method you would have to create in instance of the particular
class such as:

MyClassType MyInstance = new MyClass();

Then call the method and return the value to a Table object:

Table MyTable = MyInstance.Tabl eGenerator;

To display the table you just need to ad it to the controls collection of
another control using the add or AddAt method, eg to display it on the page
at the end of the page:

Page.Controls.A dd(MyTable);

You just need to make sure the above code goes in the relevent event handler
to determin when the table get's displayed.

If you are returning a variable/object from a method in a class it is usual
to have a scope local to that method rather than exposing it as a public
variable.

"byrd48" wrote:
Hi,
If I want to dynamically build an asp:table in a class file and return
it to the caller as an object ie:

public Table TableGenerator( ){

public Table myTable = new Table();
....
....
return myTable;
}

My question is this, how do I call this method and display the
resulting table in the presentation layer. I'm sure there is more than
one way to accomplish this.

Thanks,
Jon

Apr 25 '06 #2
Hi,

byrd48 wrote:
Hi,
If I want to dynamically build an asp:table in a class file and return
it to the caller as an object ie:

public Table TableGenerator( ){

public Table myTable = new Table();
...
...
return myTable;
}

My question is this, how do I call this method and display the
resulting table in the presentation layer. I'm sure there is more than
one way to accomplish this.

Thanks,
Jon


The method name should reflect an action, so I'd rather choose
GenerateTable() or something.

The resulting table is a Control, so it has the inherited method
RenderControl, which you can call in the Page_Load method of your page,
or in the Render method of another control. The place you execute the
RenderControl method will determine where in the page the Table is rendered.

HTH,
Laurent
--
Laurent Bugnion, GalaSoft
Software engineering: http://www.galasoft-LB.ch
Private/Malaysia: http://mypage.bluewin.ch/lbugnion
Support children in Calcutta: http://www.calcutta-espoir.ch
Apr 26 '06 #3
HI and thanks, that worked.
I have another question now. I built the table dynamically in the class
file and I added quite a few imagebuttons as in:

ImageButton Slot1 = new ImageButton();
Slot1.ID = "1";

Now when I call this class, I will pass a parameter that matches the
imagebutton.ID. I want to write a function to find which imagebutton
the parameter matches to, then dynamically assign the imageurl
property. In english terms, I want it to do something like:

find imagebutton with ID 1 and assign imageurl = "someimage.jpg" .

My question is how do I either loop through the control collection, or
search for the specific control?
Thanks much,

Jon

Apr 27 '06 #4
I'd like to clarify on the previous post.
If I define a new image button inside the class as mentioned
previously, what is the container I would reference to loop through the
controls?
If I added it to another control on the page, I could reference it by:

foreach (control c in table1.controls )

Where I'm having trouble now is finding the parent container to loop
through.
Thanks,
Jon

Apr 27 '06 #5
Hi,

byrd48 wrote:
I'd like to clarify on the previous post.
If I define a new image button inside the class as mentioned
previously, what is the container I would reference to loop through the
controls?
If I added it to another control on the page, I could reference it by:

foreach (control c in table1.controls )

Where I'm having trouble now is finding the parent container to loop
through.
Thanks,
Jon


The children controls of a page or of a control can be accessed with the
Controls collection. Actually, the Page class is derived from the
Control class, so pretty much everything you can do with a control, you
can also do it with the Page. The HtmlControl and WebControl classes are
also derived from the Control class.

To check if a Control has children or not, you can use the HasControls
property.

Though I don't mind answering on the newsgroup :-) you will be faster if
you check the MSDN documentation, which either comes with Visual Studio,
or is available online at
http://msdn1.microsoft.com/en-us/default.aspx

For example:
http://msdn2.microsoft.com/en-us/lib...l_members.aspx

HTH,
Laurent
--
Laurent Bugnion, GalaSoft
Software engineering: http://www.galasoft-LB.ch
Private/Malaysia: http://mypage.bluewin.ch/lbugnion
Support children in Calcutta: http://www.calcutta-espoir.ch
Apr 27 '06 #6
Thank you for your assistance. I look through the help files and do
web searches extensively before posting to see if I can learn on my
own.
I got the above item to work by creating an array of imagebuttons which
I could easily access programmaticall y. However, in a related issue,
When I dynamically add these imagebuttons to the table, I would like to
add a click event to them to wire back to the code page, similar to the
OnCommand event I used to use in 1.x and VB.NET. I can add commandname
and commandargs to the control at run time, but the trick now is how to
access them when I load this table into the calling page.
I guess this is the same question as before, I'm not getting a handle
on containers.

Thanks again.

Jon

Apr 28 '06 #7
Hi,

byrd48 wrote:
Thank you for your assistance. I look through the help files and do
web searches extensively before posting to see if I can learn on my
own.
No problems, I was not sure if you were aware of the online documentation.
I got the above item to work by creating an array of imagebuttons which
I could easily access programmaticall y. However, in a related issue,
When I dynamically add these imagebuttons to the table, I would like to
add a click event to them to wire back to the code page, similar to the
OnCommand event I used to use in 1.x and VB.NET. I can add commandname
and commandargs to the control at run time, but the trick now is how to
access them when I load this table into the calling page.
I guess this is the same question as before, I'm not getting a handle
on containers.

Thanks again.

Jon


I fear that I cannot help more in this issue. I don't fully understand
the question, so it migh be over my head ;-)

I hope someone else can help.

Greetings
Laurent
--
Laurent Bugnion, GalaSoft
Software engineering: http://www.galasoft-LB.ch
Private/Malaysia: http://mypage.bluewin.ch/lbugnion
Support children in Calcutta: http://www.calcutta-espoir.ch
Apr 29 '06 #8

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

Similar topics

2
6071
by: delisonews | last post by:
I'm looking for a simple, filesystem-based message board. (No MySQL!) Something that I could include easily in my code: include '../inc/messageboard.php'; .... so that the board shows up at the bottom of every PHP page. The board should have just the basic features, like: - posting capability
3
3675
by: Patchwork | last post by:
Hi Everyone, Please take a look at the following (simple and fun) program: //////////////////////////////////////////////////////////////////////////// ///////////// // Monster Munch, example program #include <list>
8
6488
by: Dan | last post by:
Using XML::Simple in perl is extreemly slow to parse big XML files (can be up to 250M, taking ~1h). How can I increase my performance / reduce my memory usage? Is SAX the way forward?
6
2055
by: Manuel Collado | last post by:
I would like to write simple, yet well structured documents with a really simple XML DTD (or schema). Either Docbook or SDocbook are overkill for this simple case. XHTML is simpler, but unstructured (no nested sections). And is not really very simple. Before trying to setup a stripped-down document format by myself, I would like to know...
11
2690
by: JKop | last post by:
Take the following simple function: unsigned long Plus5Percent(unsigned long input) { return ( input + input / 20 ); } Do yous ever consider the possibly more efficent:
4
2093
by: Steven Blair | last post by:
I have the following number: 64521234567890 and need to apply some sort of simple encryption. Does c# have any classes for doing this. I cant use 3DES or anything as complex as. The size of the string cannot increase either (no more than 14 chars) and must be numeric only.
7
2274
by: abcd | last post by:
I am trying to set up client machine and investigatging which .net components are missing to run aspx page. I have a simple aspx page which just has "hello world" printed.... When I request that page like http://machinename/dir1/hellp.aspx instead of running that page it starts downloding ...whats missing here ....why the aspx engine...
24
6313
by: firstcustomer | last post by:
Hi, Firstly, I know NOTHING about Javascript I'm afraid, so I'm hoping that someone will be able to point me to a ready-made solution to my problem! A friend of mine (honest!) is wanting to have on his site, a Javascript Calculator for working out the cost of what they want, for example: 1 widget and 2 widglets = £5.00
14
2968
by: Giancarlo Berenz | last post by:
Hi: Recently i write this code: class Simple { private: int value; public: int GiveMeARandom(void);
10
2120
by: Phillip Taylor | last post by:
Hi guys, I'm looking to develop a simple web service in VB.NET but I'm having some trivial issues. In Visual Studio I create a web services project and change the asmx.vb file to this: Imports System.Web.Services Imports System.Web.Services.Protocols Imports System.ComponentModel <System.Web.Services.WebService(Namespace:="http://...
0
7911
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7839
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8200
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8338
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7954
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6610
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
3864
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2345
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 we have to send another system
1
1448
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.