Codegeneration in custom webcontrols

P

Patrik Lindholm

Hi!

I'm fiddling around with CodeDom and codegenration.
I've looked at some samples which adds comments
and a methodcall but I want to do more.

I´ve created a control with a linkbuttoncollection where
you can add and remove linkbuttons as you like,
change properties in the collectioneditor for
each linkbutton. There is a custom property
which I've called "RedirectToPage" where
you can select a page to redirect to when you
click the linkbutton.
The control also have an event called "ItemClick"
which i want to add code for when I drop the control
onto a webform.
The code shoul look something like the code below except for the comments

// Code sample
// In InitializeComponent
MyMenuControl myMenuControl1

myMenuControl1.ItemClick += new
ItemClickHandler(this.myMenuControl_ItemClick);
// End InitializeComponent

// Eventhandler
private void myMenuControl_ItemClick(object sender, EventArgs e)
{
if("MyMenuControlItem" = = sender.GetType().ToString())
{
MyMenuControlItem mItem = (MyMenuControlItem)sender;

Response.Redirect(mItem.RedirectToPage);
}
}

Is it possible to do this.

Thank you in advance.

// Patrik
 
J

John Saunders

Patrik Lindholm said:
Hi!

I'm fiddling around with CodeDom and codegenration.
I've looked at some samples which adds comments
and a methodcall but I want to do more.

I´ve created a control with a linkbuttoncollection where
you can add and remove linkbuttons as you like,
change properties in the collectioneditor for
each linkbutton. There is a custom property
which I've called "RedirectToPage" where
you can select a page to redirect to when you
click the linkbutton.
The control also have an event called "ItemClick"
which i want to add code for when I drop the control
onto a webform.
The code shoul look something like the code below except for the comments

// Code sample
// In InitializeComponent
MyMenuControl myMenuControl1

myMenuControl1.ItemClick += new
ItemClickHandler(this.myMenuControl_ItemClick);
// End InitializeComponent

// Eventhandler
private void myMenuControl_ItemClick(object sender, EventArgs e)
{
if("MyMenuControlItem" = = sender.GetType().ToString())
{
MyMenuControlItem mItem = (MyMenuControlItem)sender;

Response.Redirect(mItem.RedirectToPage);
}
}

Is it possible to do this.

I haven't previously seen an example of using CodeDOM with web forms
controls, which persist their properties to the .aspx file and not to code
like Windows Forms controls do. Can you point me to an example of using
CodeDOM this way? It would be very useful to me.
 
A

Andy Smith

the codedom isn't going to be very useful with webforms. that's just not the
serialization model. I suggest you find another way to do what you want.

__
Andy Smith
 
G

Genich

A designer uses the services from the
System.ComponentModel.Design.Serialization.IDesignerSerializationManager to
serialize components into code. Visual Studio .NET, uses the
System.ComponentModel.Design.Serialization.CodeDomSerializer to generate
code for property values of components on a designer.

An object can tell the designer framework that it will
use a custom serializer for saving its state. This is done via the
System.ComponentModel.Design.Serialization.DesignerSerializerAttribute.

Visual Studio .NET only understands one type of base designer serializer,
which is an
abstract class named
System.ComponentModel.Design.Serialization.CodeDomSerializer.
 
J

John Saunders

Genich said:
A designer uses the services from the
System.ComponentModel.Design.Serialization.IDesignerSerializationManager to
serialize components into code. Visual Studio .NET, uses the
System.ComponentModel.Design.Serialization.CodeDomSerializer to generate
code for property values of components on a designer.

An object can tell the designer framework that it will
use a custom serializer for saving its state. This is done via the
System.ComponentModel.Design.Serialization.DesignerSerializerAttribute.

Visual Studio .NET only understands one type of base designer serializer,
which is an
abstract class named
System.ComponentModel.Design.Serialization.CodeDomSerializer.

This is very interesting. Do you have an example of using CodeDomSerializer
in a Web Forms designer?
 

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,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top