zoukankan
html css js c++ java
asp.net 动态加载用户控件注意
在asp.net 动态加载用户控件时要注意:
在没加载成功是不能对它设置属性的,以免带来不别要的错误!!
代码如下:
Default.aspx
1
using
System;
2
using
System.Data;
3
using
System.Configuration;
4
using
System.Web;
5
using
System.Web.Security;
6
using
System.Web.UI;
7
using
System.Web.UI.WebControls;
8
using
System.Web.UI.WebControls.WebParts;
9
using
System.Web.UI.HtmlControls;
10
using
System.Drawing;
11
public
partial
class
_Default : System.Web.UI.Page
12
{
13
14
15
16
protected
void
Page_Load(
object
sender, EventArgs e)
17
{
18
19
20
Control control
=
LoadControl(
"
~/myControl.ascx
"
);
//
加载用户控件
21
this
.Panel1.Controls.Add(control);
//
把它添加到该面板中
22
23
24
myControl myC
=
control
as
myControl;
//
获得实例
25
if
(myC
==
null
)
//
是否用户控件加载成功
26
{
27
PartialCachingControl pcc
=
control
as
PartialCachingControl;
28
if
(pcc
!=
null
) myC
=
pcc.CachedControl
as
myControl;
29
}
30
if
(myC
!=
null
) myC.BackColor
=
Color.Yellow;
//
成功设置该控件的样式
31
32
33
}
34
}
35
myControl.ascx
1
using
System;
2
using
System.Data;
3
using
System.Configuration;
4
using
System.Collections;
5
using
System.Web;
6
using
System.Web.Security;
7
using
System.Web.UI;
8
using
System.Web.UI.WebControls;
9
using
System.Web.UI.WebControls.WebParts;
10
using
System.Web.UI.HtmlControls;
11
using
System.Drawing;
12
13
public
partial
class
myControl : System.Web.UI.UserControl
14
{
15
public
Color BackColor
16
{
17
get
{
return
TextBox1.BackColor; }
18
set
{ TextBox1.BackColor
=
value; }
19
}
20
21
protected
void
Page_Load(
object
sender, EventArgs e)
22
{
23
TextBox1.Text
=
DateTime.Now.ToLongTimeString();
24
}
25
26
protected
void
Button1_Click(
object
sender, EventArgs e)
27
{
28
this
.TextBox2.Text
=
this
.TextBox1.Text;
29
}
30
}
31
查看全文
相关阅读:
Java版本及历史简述
ASCII、Unicode、UTF-8、UTF-16、GBK、GB2312、ANSI等编码方式简析
同步(Synchronous)和异步(Asynchronous)方法的区别
例10-12 *uva1637(概率dp)
例10-11 uva11181
例10-10 uva10491(简单概率)
例10-9 uva1636简单概率问题
全排列hash-康拓展开
10-8 uva1262密码
例10-6 uva1635(唯一分解定理)
原文地址:https://www.cnblogs.com/cfam/p/563795.html
最新文章
ccpc湘潭邀请赛 Partial Sum
hdu 1969 pie 卡精度的二分
Codeforces Round #406 (Div. 2) A MONSTER
codeforce C. Success Rate
BZOJ_3398_[Usaco2009 Feb]Bullcow 牡牛和牝牛_组合数学
BZOJ_4804_欧拉心算_欧拉函数
BZOJ_1954_Pku3764 The xor-longest Path_Trie树
BZOJ_1100_[POI2007]对称轴osi_KMP+计算几何
BZOJ_3879_SvT_后缀数组+单调栈
BZOJ_1797_[Ahoi2009]Mincut 最小割_最小割+tarjan
热门文章
STL--set/multiset用法
BZOJ_4476_[Jsoi2015]送礼物_01分数规划+单调队列
BZOJ_1654_[Usaco2007 Open]City Horizon 城市地平线_扫描线
BZOJ_2679_[Usaco2012 Open]Balanced Cow Subsets _meet in middle+双指针
MySQL数据库基础-JAVA
比特(bit)和字节(Byte)
矩阵和向量的导数运算
简析P和NP问题的概念
CPU如何区分溢出和自然进位?
C++参数传递与STL
Copyright © 2011-2022 走看看