zoukankan
html css js c++ java
自定义控件之改进的Hello控件
改进后的Hello.cs需要重编译一次,再把新生成的DLL文件拷贝至UI层的Bin文件夹
改进后的Hello.cs
using
System;
using
System.Web.UI;
using
System.Collections.Generic;
using
System.ComponentModel;
using
System.Data;
using
System.Drawing;
using
System.Text;
using
System.Windows.Forms;
namespace
BLL
{
public
partial
class
Hello : System.Web.UI.Control
{
/**/
/*
在BLL层右键Add---〉CustomControl会自动产生下面的一个构造器
* 和一个OnPaint方法---〉怀疑和using System.Windows.Forms;有关
*/
//
public Hello()
//
{
//
InitializeComponent();
//
}
//
protected override void OnPaint(PaintEventArgs pe)
//
{
//
//
TODO: Add custom paint code here
//
//
Calling the base class OnPaint
//
base.OnPaint(pe);
//
}
string
MyName
=
""
;
public
string
Name
{
get
{
return
MyName; }
set
{ MyName
=
value; }
}
protected
override
void
Render(HtmlTextWriter writer)
{
//
base.Render(writer);
writer.Write(
"
<h1>Hello,
"
+
Name
+
"
</h1>
"
);
}
}
}
改进后的aspx(只是<win:hello 多了个属性:Name)
<%
@ Page Language
=
"
C#
"
AutoEventWireup
=
"
true
"
CodeFile
=
"
hello.aspx.cs
"
Inherits
=
"
hello
"
%>
<%
@ Register TagPrefix
=
"
win
"
Namespace
=
"
BLL
"
Assembly
=
"
HelloControl
"
%>
<
html
xmlns
="http://www.w3.org/1999/xhtml"
>
<
head
runat
="server"
>
<
title
>
CustomControl Page
</
title
>
</
head
>
<
body
>
<
form
id
="form1"
runat
="server"
>
<!--
<%@ Register TagPrefix="win" Namespace="BLL" Assembly="HelloControl" %>
该指令不需要TagName因为对于自定义控件来说:控件的类名就是它的TagName
因为public partial class Hello : System.Web.UI.Control所以控件的类名
Hello就是这里的TagName
而Namespace和Assembly是一定要有的,这里Assembly="HelloControl"是因为:
csc /t:library /out:HelloControl.dll hello.cs
-->
<!--
这里<win:Hello 控件的行为完全由BLL层中的Hello.cs决定
与本aspx和aspx.cs完全无关
-->
<!--
如果机器较慢 智能感知可能不会很及时地反应出Name属性来
-->
<
win:Hello
ID
="cutomControl1"
Name
="Jeff"
runat
="server"
></
win:Hello
>
</
form
>
</
body
>
</
html
>
查看全文
相关阅读:
Web安全测试检查点
"Could not resolve host: mirrorlist.centos.org; Unknown error"解决方法
VMware vSphere Client中启动虚拟机提示No boot filename received/Operating System not found解决方法
Android:Mstar Android8.0平台音量控制流程
Android:系统自定义鼠标样式切换
Android:系统日历添加默认账户
Android:状态栏禁用时蓝牙多文件传输弹窗及进度显示
Android:导入所需的系统jar包到Android studio
Android:修改连接到AP端显示的设备名
Android:StateMachine 之 WifiStateMachine
原文地址:https://www.cnblogs.com/simhare/p/827201.html
最新文章
JSON风格指南
Android Activity去除标题栏和状态栏
LayoutInflater这个类还是非常有用的,它的作用类似于findViewById()。 但他是找XML文件并实例化
网站502与504错误分析
大流量高并发站点终极优化方案,十分钟让网站性能提升10倍
微信网页扫码登录的实现
浅谈Hybrid技术的设计与实现
超赞!聊聊WEB APP、HYBRID APP与NATIVE APP的设计差异
图片存储架构学习:独立的图片服务器,给爱一个独立的空间
javascript模块化编程库require.js的用法
热门文章
Nginx 开启gzip压缩(图片,文件,css)
网站打开速度慢的原因,排查方法及优化方法
在页面加载后在设置embed 的src 怎么实现?
Python3.7离线安装Requests无法正常使用问题
离线安装MySQLdb for Python3.7
Python安装tar.gz格式文件方法小结
JMeter报Non HTTP response code: org.apache.http.conn.HttpHostConnectException
接口测试用例编写规范
戴明品质管理十四法
微信小程序测试检查点
Copyright © 2011-2022 走看看