473,320 Members | 1,978 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.

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 1060
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.TableGenerator;

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.Add(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 programmatically. 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 programmatically. 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
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...
3
by: Patchwork | last post by:
Hi Everyone, Please take a look at the following (simple and fun) program: //////////////////////////////////////////////////////////////////////////// ///////////// // Monster Munch, example...
8
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
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...
11
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
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...
7
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...
24
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...
14
by: Giancarlo Berenz | last post by:
Hi: Recently i write this code: class Simple { private: int value; public: int GiveMeARandom(void);
10
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...
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...
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: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
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: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
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
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
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.