ASP. NET custom control development and design interface (the design interface is different from the runtime Interface)

Source: Internet
Author: User

Design:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
namespace ServerControl2
{
public class Des:System.Web.UI.Design.ControlDesigner
{
public override string GetDesignTimeHtml()
{
StringWriter sw = new StringWriter();
HtmlTextWriter tw = new HtmlTextWriter(sw);
HyperLink hl = new HyperLink();
hl.Text = "Hello, Control";
hl.NavigateUrl = "http://www.microsoft.com/china/msdn";
hl.RenderControl(tw);
tw.Write(HtmlTextWriter.SpaceChar);
Label lbl = new Label();
lbl.BackColor = System.Drawing.Color.LemonChiffon;
lbl.Text = hl.NavigateUrl;
lbl.RenderControl(tw);
return sw.ToString();
}
}
}
Using system;
Using system. Collections. Generic;
Using system. componentmodel;
Using system. LINQ;
Using system. text;
Using system. Web;
Using system. Web. UI;
Using system. Web. UI. webcontrols;

Namespace servercontrol2
{

[Designer ("servercontrol2.des, servercontrol2"), defaultproperty ("text")]
[Toolboxdata ("<{0}: servercontrol1 runat = Server> </{0}: servercontrol1>")]
Public class servercontrol1: webcontrol, ipostbackeventhandler
{
[Bindable (true)]
[Category ("appearance")]
[Defaultvalue ("")]
[Localizable (true)]
Public String text
{
Get
{
String S = (string) viewstate ["text"];
Return "custom control AA ";
}
Set
{
Viewstate ["text"] = value;
}
}
Public int speed
{
Get;
Set;
}

Protected override void rendercontents (htmltextwriter output)
{
Output. Write (text );
Output. Write (string. Format (@ "<marquee width = 400 scrollamount = '{0}' behavior = alternate direction = left align = middle>! </Marquee> ", speed ));

}
Protected override void onprerender (eventargs E)
{

}
Protected override void addattributestorender (htmltextwriter writer)
{
Writer. addattribute (htmltextwriterattribute. onclick, "javascript:" + Page. getpostbackeventreference (this ));
Writer. addstyleattribute (htmltextwriterstyle. backgroundcolor, "Red ");
Base. addattributestorender (writer );
}
Public event eventhandler click;
Public void raisepostbackevent (string eventargument)
{
Onclick (eventargs. Empty );
}
Protected virtual void onclick (eventargs ex)
{
If (Click! = NULL)
{
Click (this, ex );
}
// Httpcontext. Current. response. Redirect ("http://www.baidu.com ");

}
}
}

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.