Adding Control programmatically in Custom Designer

T

Tom

Hi,

i'm stuck with a problem that bothers me the last 2 days...

Here's the scenario :

I have a custom Control (FieldContainer) that acts as a container for other
custom controls.
FieldContainer extends the standard WebControl Pane and has a custom
Designer attached, which extends
ReadWriteControlDesigner.
The plan is to have 2 DesignerVerbs in that designer; one Verb is to save
the controls in the container to a database,
the other Verb should load Controls from the database and populate the empty
container.
Saving the controls works already, but creating controls doesn't seem to
work.
As a test, i tried to create a single control.


Here is code from the Designer :

public class FieldContainerDesigner : ReadWriteControlDesigner
{
DesignerVerbCollection verbs;

public override System.ComponentModel.Design.DesignerVerbCollection Verbs
{
get
{
verbs = new DesignerVerbCollection();
verbs.Add(new DesignerVerb("Save to DB", new EventHandler(OnSaveToDb)));
// Save controls to DB
verbs.Add(new DesignerVerb("Create RID", new
EventHandler(OnCreateRequestId))); // Test: create a single control
return verbs;
}
}

private void OnCreateRequestId(object sender, EventArgs e)
{
FieldContainer fc = (FieldContainer)Component;
if (fc.NextFieldId == 0) // Container is empty ?
{
fc.NextFieldId = 0x20000001; // set next DB Id
IDesignerHost host = (IDesignerHost)GetService(typeof(IDesignerHost));
if (host != null)
{
DesignerTransaction dt;
IComponentChangeService c =
(IComponentChangeService)GetService(typeof(IComponentChangeService));
dt = host.CreateTransaction("New ReqId");
IComponent comp = host.CreateComponent(typeof(SVOTextBox));
c.OnComponentChanging(fc, null);
SVOTextBox reqId = (SVOTextBox)comp; // Create custom TextBox
reqId.DBId = 1;
reqId.DBLength = 15;
reqId.LabelText = "Request ID"; // Set Parameters
reqId.ID = "RequestId";
fc.Controls.Add(reqId);
c.OnComponentChanged(fc, null, null, null);
dt.Commit();
UpdateDesignTimeHtml();
}
}
}


When the method OnCreateRequestId is executed, a new custom TextBox should
be created in the container.
What happens is that there IS a control (i can select it in the property
browser and it has all properties attached correctly,
even a variable in my .cs-File is generated), but there is NO control in the
designer !
Furthermore, when i switch to HTML-View and back to Design-View the control
is gone....

Does anybody has a clue on how to make the control visible to the designer ?

Thank you,
Tom
 

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

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,067
Latest member
HunterTere

Latest Threads

Top