Asp.Net自定义控件的开发

  基于Asp.Net的控件开发涉及到两种,一种是用户控件,即通过vs自带的服务器控件进行组合以开发需求,该类控件的开发相对简单;另一种是自定义控件,开发难度较高。

1、在vs中新建一个类库的项目WebControl,添加对System.Web.UI程序集的引用,

2、在项目的AssemblyInfo.cs文件中添加“using System.Web.UI”等代码,代码如下所示:

复制代码
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Web.UI;    //自行添加

// General Information about an assembly is controlled through the following 
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("WebControl")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("WebControl")]
[assembly: AssemblyCopyright("Copyright ©  2016")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// Setting ComVisible to false makes the types in this assembly not visible 
// to COM components.  If you need to access a type in this assembly from 
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]

// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("33d4f2ba-7cf9-49a7-9b86-442e3beba5e9")]

// Version information for an assembly consists of the following four values:
//
//      Major Version
//      Minor Version 
//      Build Number
//      Revision
//
// You can specify all the values or you can default the Build and Revision Numbers 
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

/*自行添加*/
[assembly: WebResource("WebControl.resource.css.webctl.css", "text/css", PerformSubstitution = true)]
[assembly: WebResource("WebControl.resource.js.webctl.js", "application/x-javascript", PerformSubstitution = true)]
[assembly: WebResource("WebControl.resource.js.webctl.png", "image/png")]
复制代码

2、添加一个类文件customcontrol.cs,编写如下代码:

posted @   飞仔FeiZai  阅读(75)  评论(0编辑  收藏  举报
编辑推荐:
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
· 一个奇形怪状的面试题:Bean中的CHM要不要加volatile?
· [.NET]调用本地 Deepseek 模型
· 一个费力不讨好的项目,让我损失了近一半的绩效!
阅读排行:
· 百万级群聊的设计实践
· 永远不要相信用户的输入:从 SQL 注入攻防看输入验证的重要性
· 全网最简单!3分钟用满血DeepSeek R1开发一款AI智能客服,零代码轻松接入微信、公众号、小程
· .NET 10 首个预览版发布,跨平台开发与性能全面提升
· 《HelloGitHub》第 107 期
点击右上角即可分享
微信分享提示