pass table back to webpage

G

Guest

I'm wondering what the best way to do the following:
I have a page with a table. I built a custom class that creates a
System.Web.UI.WebControls table object and return it to the webpage as a
property. But its not reading the table correctly. It doesnt see the
tablerows and tablecell objects.
First, I'm not sure why its not reading the table properly?
Second, I wonder if there's a better way to do this? Maybe a custom control?
I haven't really gotten into these yet. My table only contains some
hyperlinks to open other pages. so no other server-side processing after
this.
 
P

Patrice

What do you mean by "Not reading the table properly". If collections are
empty could it be you forgotten to add them asd they are created to your
table ?

Patrice
 
G

Guest

The table in the webpage is set to the returned table from the custom class
function. I know that there's data rows and cells in it.
on webpage:
objBusLog.FillTable(); //this is call to define the table
TblRpt = objBusLog.TblReports; //This sets table web control to actual
table being set in custom class.

??
 
P

Patrice

What I don't understand for now is the result you have.

Do you mean you have no HTML at all rendered for this table ?
If yes, it's likely this control is not part of the page.

Do you mean you have rows missing ? What if you show the rows count to see
if it's what you expect ?
If not it's likely rows are not added in the collection...

Etc...

Some basic code would be :

System.Web.UI.WebControls.Table TestFunction()
{
System.Web.UI.WebControls.Table t=new System.Web.UI.WebControls.Table();
System.Web.UI.WebControls.TableRow r=new
System.Web.UI.WebControls.TableRow();
System.Web.UI.WebControls.TableCell c=new
System.Web.UI.WebControls.TableCell();
r.Cells.Add(c);
t.Rows.Add(r);
return t;
}
void Page_Load(Object sender,System.EventArgs e)
{
Form1.Controls.Add(TestFunction());
}

(use "view source" in your browser to see that it renders an empty HTML
table).

Hope it helps...

Patrice

--
 
G

Guest

Yes, the table is indeed a server side control. If I run the code directly in
the page_load, to build the table, all is good, like the way, your test
function is setup..

But in my case, I create a new class that creates the table. Then I get a
property as follows:
public System.Web.UI.WebControls.Table TblReports
{
get
{
return m_objTblRpts;
}
} }
When I print the number of rows in the web page, it comes back as 2. But it
doesnt actually print the rows of the table. It only prints the following:
<table id="TblRpts" border="0" style="width:928px;Z-INDEX: 108; LEFT: 24px;
POSITION: absolute; TOP: 352px">

Can I not return a table in a class property????
 
P

Patrice

It looks like to me you are assigning TblRpts a *new* object and that you
would expect this new object to be rendered.

Actually behind the scene this object is registered in the "Controls"
collection before your code runs. As a result, assigning a *new* object to
this object variable won't have any effect (keep in mind that objects
variables are nothing else than "pointers").

I see basically two solutions :
- add the *new* control to the controls collection (and you don't need to
have the TblRpts controls in your page)
- pass TblRpts to your function so that you can add rows to the existing
control rather than creating a new one

Hope it helps...

Patrice

--
 
G

Guest

Thanks. That was it!
Appreciate it.

That leads back to the first question:
I'm trying to do this using a fairly good 'object-oriented' methodology. So
creating a new class to build a table, and return the table.. Is that the
best method?
 
P

Patrice

Depending on what it does you could create a control (in particular it
allows if applicable to provide some design time support).
You could also expose this a as "static" function depending on wether or not
it contains a state...

The key point is IMO to keep each part in its own layer and only using well
defined interactions with other parts, not doing things "OO" for its own
sake. As long as you do this, it will be easier to evolve each part
separately...

Patrice

--
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,773
Messages
2,569,594
Members
45,121
Latest member
LowellMcGu
Top