访问器WebControls在构造函数中的ASP网可标记属性 [英] access WebControls markable properties in constructor asp net
本文介绍了访问器WebControls在构造函数中的ASP网可标记属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
下面是我的自定义control.It从Control继承class.I [高度]属性要访问它的构造函数来计算其他properties.But其值始终0.Any想法?
公共类MyControl:WebControl的,IScriptControl
{ 公共MyControl()
{
AnotherProperty计算=(身高);
.......
}
我的aspx
<马力:MyControl身高=31px... />
解决方案
标记值是不是在你的控件的构造函数可用,但他们可以从你的控件的OnInit事件中。
保护覆盖无效的OnInit(EventArgs的发送)
{
//具有价值,即使在被称为基地的OnInit()方法之前
VAR HEIGHT = base.Height; base.OnInit(E);
}
Here is my custom control.It inherits [Height] property from WebControl class.I want to access it in constructor for calculating other properties.But its value is always 0.Any idea?
public class MyControl : WebControl, IScriptControl
{
public MyControl()
{
AnotherProperty = Calculate(Height);
.......
}
my aspx
<hp:MyControl Height = "31px" .... />
解决方案
Markup values are not available in your control's constructor but they are available from within your control's OnInit event.
protected override void OnInit(EventArgs e)
{
// has value even before the base OnInit() method in called
var height = base.Height;
base.OnInit(e);
}
这篇关于访问器WebControls在构造函数中的ASP网可标记属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文