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
>
查看全文
相关阅读:
高精度A+B
基本定积分求面积
二进制算子集和
linux命令
Dubbo
java 集合区别
Java中Comparable和Comparator区别
synchronized实现原理
ThreadLocal 原理
java volatile关键字
原文地址:https://www.cnblogs.com/simhare/p/827201.html
最新文章
Activiti 基础介绍
Mybatis-Plus 基础
Layui 基础
Linux User And Group Management
hge引擎示例教程cmake项目
jupyter修改根目录
使用动态链接为什么还需要静态库lib文件
数据库课程设计:SQL Server + Express + node.js + ejs 论坛管理系统
Promise.then返回的是什么?
多次调用Promise的then会返回什么?
热门文章
node.js 出现server instance pool was destroyed
node mssql 无法连接sql server
Ubuntu无法安装 英伟达显卡
电脑快捷键
WPF中矢量图标库
快速幂取模拓展
扩展欧拉定理—降幂大法
矩阵快速幂取模
阶乘末尾零数
进制转换
Copyright © 2011-2022 走看看