Custom Control Table member variable broke

  • Thread starter Thread starter Troy
  • Start date Start date
T

Troy

I have been trying for 2 weeks to figure out how to
implement a table as a member variable that the user can
setup with the property designer with no luck. The code
below adds the table to the property designer, however it
will not write the HTML associated with the TABLE within
the custom server control tags unless you change the font
property within the table. For instance you can set the
ID of the table and its height and width then hit rebuild
and it all gets blown away because the table does'nt get
serialized.However set the ID,Width and Height again this
time change the Font property of the table to bold and it
magically writes the HTML code as shown in result 2,
which is exactly correct and what I want. Changing any
property value in the font of the table somehow triggers
VS to write the correct HTML..but changing any of the
table attributes doesnt do anything..you have to change
the font to get it to make any change...............

using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.ComponentModel;
using System.Drawing.Design;
using System.Web.UI.Design;

namespace RealGridII
{
/// <summary>
/// Summary description for WebCustomControl1.
/// </summary>

[ToolboxData("<{0}:RealGridControl runat=server></
{0}:RealGridControl>")]
public class RealGridControl :
System.Web.UI.WebControls.DataGrid
{
private Table m_myHeader;

/// <summary>
/// Constructor
/// </summary>
public RealGridControl()
{
m_myHeader = new Table();
}

[Category("LookHere"),NotifyParentProperty
(true),DesignerSerializationVisibility
(DesignerSerializationVisibility.Content),PersistenceMode
(PersistenceMode.InnerProperty)]
public Table myDatagrid
{
get
{
return m_myHeader;
}
set
{
m_myHeader = value;
}
}

/// <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)
{
m_myHeader.RenderControl(output);
base.Render(output);

}
}
}

Result #1:
<form id="Form1" method="post" runat="server">
<cc1:realgridcontrol
id="RealGridControl2" style="Z-INDEX: 101; LEFT: 400px;
POSITION: absolute; TOP: 184px"
runat="server"
DataSource="<%# dataView1 %>" AutoGenerateColumns="False">

<Columns>
<asp:BoundColumn
DataField="EmployeeID" SortExpression="EmployeeID"
HeaderText="EmployeeID"></asp:BoundColumn>
<asp:BoundColumn
DataField="LastName" SortExpression="LastName"
HeaderText="LastName"></asp:BoundColumn>
<asp:BoundColumn
DataField="FirstName" SortExpression="FirstName"
HeaderText="FirstName"></asp:BoundColumn>
</Columns>
</cc1:realgridcontrol></form>



Result #2
<form id="Form1" method="post" runat="server">
<cc1:realgridcontrol
id="RealGridControl2" style="Z-INDEX: 101; LEFT: 400px;
POSITION: absolute; TOP: 184px"
runat="server"
DataSource="<%# dataView1 %>" AutoGenerateColumns="False">
<myDatagrid Font-
Bold="True" ID="fuku"></myDatagrid>
<Columns>
<asp:BoundColumn
DataField="EmployeeID" SortExpression="EmployeeID"
HeaderText="EmployeeID"></asp:BoundColumn>
<asp:BoundColumn
DataField="LastName" SortExpression="LastName"
HeaderText="LastName"></asp:BoundColumn>
<asp:BoundColumn
DataField="FirstName" SortExpression="FirstName"
HeaderText="FirstName"></asp:BoundColumn>
</Columns>
</cc1:realgridcontrol></form>
 
Hi,

If you are looking for "UI type editor"[1] then I didn’t see that you
implement UI type editor class to the "table" property. You first need
to create your own class that derives from UITypeEditor. Then you need
to use the Editor attribute for that property [2].

I strongly recommand you to get a copy of :
Developing Microsoft ASP.NET Server Controls and Components
By Nikhil Kothari, Vandana Datje


[1] A class that is associated with a type or a property and provides a
specialized user interface for editing a property. A UI type editor is
launched from the property browser and is useful when the simple text
entry UI provided by the property browser is not adequate for editing a
property. For example, the color picker drop-down list within the
property grid that enables a page developer to select a color for the
BackColor or ForeColor property of a Web control in a WYSIWYG fashion is
a UI type editor. We'll show you how to implement UI type editors in the
"UI Type Editors" section in this chapter.

[2]
[Editor(typeof(MyStringEditor),
typeof(UITypeEditor))
]
public override Table Text {
get {
...;
}
set {
...;
}
}


Natty Gur, CTO
Dao2Com Ltd.
28th Baruch Hirsch st. Bnei-Brak
Israel , 51114

Phone Numbers:
Office: +972-(0)3-5786668
Fax: +972-(0)3-5703475
Mobile: +972-(0)58-888377

Know the overall picture
 
I have purchased this book last night and begun reading. However, the
Table UI editor is already built into VS and should be reusable.Every
sample in the book and online only uses a super custom class as an
example in which you have to go overide all these methods but this is
your standard table with no frills just like FontInfo,ImageEditor,URL
builder and Color. If your test this code it makes a beautiful table and
does everything it should do. VS automatically chooses the correct
Editor based on a table and its even reflected in the design view. But
the code isn't getting serialized when you change the table properties
only if you change the tables font property. I bought this book solely
to answer this question and the only thing close to this is writing a
property for every attribute of a table as shown in the example on page
220. Any help will be greatly appreciated....
 
Back
Top