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
>
查看全文
相关阅读:
【python cookbook】替换字符串中的子串(使用Template)
python 学习sys
【python cookbook】 替换字符串中的子串
Python文件读写
【python cookbook】python过滤字符串中不属于指定集合的字符
【python cookbook】改变多行文本字符串的缩进
python字符编码
【python cookbook】python访问子字符串
【python cookbook】python 控制大小写
过关了
原文地址:https://www.cnblogs.com/simhare/p/827201.html
最新文章
linux下vsftpd架设ftp服务器
Linux上iptables防火墙的基本应用教程
windows使用ssh2远程登陆ubuntu
Linux权限说明
关于mysql命令行的一些操作
Tomcat7.0添加管理用户的xml内容,在ubuntu下通过
一些ghost版本的xp不能远程的问题
Berkeley DB Java Edition使用说明
java 获取绝对路径
Quartus中的打印设置
热门文章
nios中优化代码和减少程序占用内存空间的设置方法
找回quartus中pin planner中分配引脚的对话框 (转载)
常见的PCB工具软件介绍【转载】
条件编译命令 `ifdef、`else、`endif 的用法
时间尺度`timescale
SRAM,DRAM,SDRAM关系的区别(转载)
时间单位之间的转换
Quartus中仿真时出现no simulation input file assignment specify 解决方法 (转载)
nios中的头文件上的#include<>和#include""的区别
【python cookbook】python检查一个字符串是文本还是二进制
Copyright © 2011-2022 走看看