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
>
查看全文
相关阅读:
网络状态码含义——(比如204,304, 404, 504,502)
Vue两个简易代替vuex的方法(eventBus,observable)
单页面首屏加载慢解决方案
前端监控和前端埋点
ES5 和 ES6的继承
mysql 隔离级别
mysql 事务
Seata
Sentinel Dashboard 部署
java 垃圾回器
原文地址:https://www.cnblogs.com/simhare/p/827201.html
最新文章
Spring Boot 集成 ShardingSphere 实现分表
Docker ES Install IK
使用 Canal 增量同步 MySQL 到 ES (下)
使用 Canal 增量同步 MySQL 到 ES (上)
Canal Adapter com.alibaba.druid.pool.DruidDataSource cannot be cast to com.alibaba.druid.pool.DruidDataSource
Spring Boot 集成 ShardingSphere 实现读写分离
Spring Boot 集成 MyBatis-Plus
使用JProfiler 分析 OOM
.NET MVC框架中控制器接收参数的四种方式
MVC4 的 Web API 接口
热门文章
住上铺的师兄面试去了TX,就因为他和面试官光红黑树就聊了半个小时,建议收藏
掌握了2-3-4树也就掌握了红黑树,不信进来看看,建议收藏!
Java集合核心内容之二叉树,大厂越来越注重基础了,建议收藏
2021全网最全Activiti7教程05(Activiti7整合篇-欢迎收藏)
2021全网最全Activiti7教程04(Activiti7进阶篇-欢迎收藏)
2021全网最全Activiti7教程03(Activiti7基本操作-欢迎收藏)
2021全网最全Activiti7教程02(Activiti7入门使用-欢迎收藏)
2021全网最全Activiti7教程01(Activiti7详细介绍-欢迎收藏)
vue代码优化问题
web安全防御与优化
Copyright © 2011-2022 走看看