Asp.net|server asp.net server Control-time Support
Have you done your own ASP.net server control? Is there anything like the ASP.net DataGrid control:
1. Pull it out of the Toolbox and automatically generate a bunch of code
2. Right click to see attributes, there are a lot of custom attribute
3. You can also go into template edit mode and drag the textbox in Toolbox into your control.
4. You can even pop up a dialog box of your own to make a huge, complex configuration.
I spent a day looking at how to do these things, although I found out that I don't need these features at the moment but still
Willing to share with you, some things you do not go to see really do not know so simple, as the same thing you read
Find it so complicated.
Main document: (note URL wrap)
MSDN Lib:enhancing Design-time Support
http://msdn.microsoft.com/library/default.asp?
Url=/library/en-us/cpguide/html/cpconenhancingdesign-timesupport.asp
The PDC02 session 407 names are like build asp.net server control.
In the first paragraph of the MSDN documentation, you get straight to the point:
In the. NET Framework, the work for design-time support are not delegated to a
Design environment such as Visual Studio. NET but is enabled through a rich
Built-in Design-time architecture.
So what you're going to do is not vs.net add-on, it's a direct extension of your control.
1. Pull it out of the Toolbox and automatically generate a bunch of code
This is done by adding an attribute to your server control code:
(or how to say the attribute programming?)
[ToolBoxData ("<{0}:mycontrol runat=server></{0}:mycontrol>")]
public class MyControl:System.Web.UI.WebControls.DataGrid//Random Example
When you drag your control into the WebForm, it automatically generates the code music.
2. Right click to see attributes, there are a lot of custom attribute
For example, there's a property in your control that specifies the URL of the XSL file, so you can:
[
Browsable (True),
Category ("Data"),
DefaultValue ("Http://myserver/myApp/myXSL.xsl"),
Description ("Specify your XSL file URL"),
Editor (typeof (System.Web.UI.Design.XslUrlEditor),
typeof (System.Drawing.Design.UITypeEditor))
]
public string Myxsltsrc {...}
And so on, you can see your myxsltsrc in the data group of the Properties dialog box,
And you can specify this value through a special dialog box that chooses the XSL URL.
3. You can also go into template edit mode and drag the textbox in Toolbox into your control.
The free lunch is over. The rest is really going to write code.
First you have to tell the control you made a special designer for the old man:
[Designer ("YourNameSpace.Design.MyControlDesigner, YourNameSpace")]
public class MyControl:System.Web.UI.WebControls.DataGrid//Random Example
And then really give it to the elderly to do a Designer:
Namespace Yournamespace.design
{
public class MyControlDesigner:System.Web.UI.Design.WebControls.DataGridDesigner
{//Because control is inherited from the DataGrid, control designer inherits from Datagriddesigner
}
}
What's the main thing to do with this designer?
You should at least render out a piece of HTML code so that you can see it in the Design view of the Vs.net IDE
The control you have worked so hard to do.
Mainly through override these methods:
public override string GetDesignTimeHtml ()
protected override string GetEmptyDesignTimeHtml ()
For example, your control supports data binding or something, you can consider using some sample data to display.
Or do some more work. The data source specified by page developer is actually bound to be displayed.
Look at the document carefully and you'll find out how to create an edit template. After the edit template, you right click on your
Control can enter edit mode, for example, your control contains a content template, you can put the Toolbox
asp.net textbox, checkbox and other things directly drag & drop to the inside to enjoy.
4. You can even pop up a dialog box of your own to make a huge, complex configuration.
It takes a little more effort to make this happen, you have to do another mycontrolcomponenteditor,
public class MyControlComponentEditor:System.Web.UI.Design.WebControls.DataGridComponentEditor
And tell mycontrol it old man please use this Editor:
[Editor (typeof (Mycontrolcomponenteditor), typeof (ComponentEditor))]
public class MyControl:System.Web.UI.WebControls.DataGrid//Random Example
How to achieve through override methods, check the document 8.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.