Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Building Controls > Building a custom control that implement table server control

Reply
Thread Tools

Building a custom control that implement table server control

 
 
Thomas Ekegren
Guest
Posts: n/a
 
      07-19-2003
Hi,

I want to create a custom control that implements the table htmlcontrol. In
my webform page I want to include that custom control and add content to a
cell in my custom table control. I don't want to do this dynamically in the
page_load event but in the HTML design view.

Example:

My custom control containes
a table
one row
and three cells

_____________________________
| Cell1 | Cell2 | Cell3 |
_____________________________

I want to position my content in cell #2

<HTML>
<BODY>
<CustomControl:myTable id="myTable1" runat="server">

/**** this is what i want to position in cell #2 ****/
<tr>
<td>My text</td>
</tr>

</CustomControl:myTable>
</BODY>
</HTML>

Any suggestion as to how to accomplish this?

Thanks,

/ekegren


 
Reply With Quote
 
 
 
 
Victor Garcia Aprea [MVP]
Guest
Posts: n/a
 
      07-20-2003
Hi Thomas,

You could write a composite control that contains an HtmlTable control. This
composite control would allow the user to declaratively specify its child
controls, ie:

<cc:YourCompositeControl>
//contents for 2nd cell goes here
</cc:YourCompositeControl>

Then your composite control should create an HtmlTable, add one row and
three cells, and insert the specified child controls in the 2nd row.

You can find more info about composite controls and their keys method (ie.
CreateChildControls, etc) in the docs and in web tutorials. You will need
also to get familiar with attributes and the specific ones that control the
parsing and serialization of your control and its childs
(ParseChildrenAttribute, etc). There are lots of posts and samples posted in
this ng, you could use http://groups.google.com to find them and learn from
there.

Give that a try and post here any problems you encounter,


--
Victor Garcia Aprea
Microsoft MVP | ASP.NET
Looking for insights on ASP.NET? Read my blog:
http://obies.com/vga/blog.aspx
To contact me remove 'NOSPAM'. Please post all questions to the newsgroup
and not by private mail.

"Thomas Ekegren" <> wrote in message
news:...
> Hi,
>
> I want to create a custom control that implements the table htmlcontrol.

In
> my webform page I want to include that custom control and add content to a
> cell in my custom table control. I don't want to do this dynamically in

the
> page_load event but in the HTML design view.
>
> Example:
>
> My custom control containes
> a table
> one row
> and three cells
>
> _____________________________
> | Cell1 | Cell2 | Cell3 |
> _____________________________
>
> I want to position my content in cell #2
>
> <HTML>
> <BODY>
> <CustomControl:myTable id="myTable1" runat="server">
>
> /**** this is what i want to position in cell #2 ****/
> <tr>
> <td>My text</td>
> </tr>
>
> </CustomControl:myTable>
> </BODY>
> </HTML>
>
> Any suggestion as to how to accomplish this?
>
> Thanks,
>
> /ekegren
>
>



 
Reply With Quote
 
 
 
 
Victor Garcia Aprea [MVP]
Guest
Posts: n/a
 
      07-20-2003
Hi Thomas,

What I had in mind was a bit different. If I'm understanding you correctly
you want your control to only allow childs controls to be added to an
specific cell of a one-row table, is that correct? Currently in your code,
you're deriving from Table, this would allow a page developer to actually do
more than what I believe you want. He/she could add more rows, cells, etc;
is this still okay?

--
Victor Garcia Aprea
Microsoft MVP | ASP.NET
Looking for insights on ASP.NET? Read my blog:
http://obies.com/vga/blog.aspx
To contact me remove 'NOSPAM'. Please post all questions to the newsgroup
and not by private mail.

"Thomas Ekegren" <> wrote in message
news:%...
Hi Victor,
I have now managed to but content into my cell as I wanted. The problem is
that I can't get the controls that are nested inside my composite control to
be displayed properly.
So my question is how do I loop through the nested controls and get them
displayed inside the table. Could you pinpoint me in the right direction and
maybe explain why the code below does not work as intended?
/Thomas
here is my code:
Custom Control:
using System;
using System.Reflection;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.ComponentModel;
namespace cc
{
/// <summary>
/// Summary description for WebCustomControl1.
/// </summary>
[DefaultProperty("Text"),
ToolboxData("<{0}:CustomTable1 runat=server></{0}:CustomTable1>")]
[ParseChildren(false)]
public class CustomTable : System.Web.UI.HtmlControls.HtmlTable,
INamingContainer
{
private string text;
private HtmlTableCell c2 = new HtmlTableCell();
[Bindable(true),
Category("Appearance"),
DefaultValue("")]
public string Text
{
get
{
return text;
}
set
{
EnsureChildControls();
c2.InnerHtml = value;
}
}
protected override void CreateChildControls()
{
//string HtmlInsideCell2;
HtmlTableRow tblRow = new HtmlTableRow();
HtmlTableCell c1 = new HtmlTableCell();
c1.InnerHtml = "Cell1";
tblRow.Cells.Add(c1);
tblRow.Cells.Add(c2);
HtmlTableCell c3 = new HtmlTableCell();
c3.InnerHtml= "Cell3";
tblRow.Cells.Add(c3);
this.Rows.Add(tblRow);
//Controls.Add(tblRow);
}
protected override void AddParsedSubObject(Object obj)
{
//this is where the child objects are added to the cell#2
HtmlTable tbl = new HtmlTable();
if(obj.GetType() is HtmlTableRow)
{
HtmlTableRow r1 = (HtmlTableRow)obj;
tbl.Rows.Add(r1);
}
c2.Controls.Add(tbl);
}
/// <summary>
/// Render this control to the output parameter specified.
/// </summary>
/// <param name="output"> The HTML writer to write out to </param>
protected override void Render(HtmlTextWriter output)
{
base.Render(output);
}
}
}
my aspx page:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>WebForm2</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio 7.0">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema"
content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="WebForm2" method="post" runat="server">
<Custom:CustomTable id="ct1" runat="server">
<TR>
<TD>Hello World!</TD>
</TR>
</Custom:CustomTable>
</form>
</body>
</HTML>

"Thomas Ekegren" <> skrev i en meddelelse
news:...
> Hi,
>
> I want to create a custom control that implements the table htmlcontrol.

In
> my webform page I want to include that custom control and add content to a
> cell in my custom table control. I don't want to do this dynamically in

the
> page_load event but in the HTML design view.
>
> Example:
>
> My custom control containes
> a table
> one row
> and three cells
>
> _____________________________
> | Cell1 | Cell2 | Cell3 |
> _____________________________
>
> I want to position my content in cell #2
>
> <HTML>
> <BODY>
> <CustomControl:myTable id="myTable1" runat="server">
>
> /**** this is what i want to position in cell #2 ****/
> <tr>
> <td>My text</td>
> </tr>
>
> </CustomControl:myTable>
> </BODY>
> </HTML>
>
> Any suggestion as to how to accomplish this?
>
> Thanks,
>
> /ekegren
>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
problem in running a basic code in python 3.3.0 that includes HTML file Satabdi Mukherjee Python 1 04-04-2013 07:48 PM
Building a control adapter for a custom control boarding_king ASP .Net Building Controls 0 09-20-2006 10:04 AM
Custom User Control is not rendered inside another user control in a server table. Leeor Chernov ASP .Net 2 10-16-2005 08:35 AM
Building a custom table control I am Sam ASP .Net Building Controls 0 05-18-2005 10:33 AM
Building a custom server control - Property Builder Ryan Taylor ASP .Net Web Controls 0 02-08-2005 02:06 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57