我给一个自定义控件(继承自Button)新增了一个属性ButtonType(枚举类型,包括"新增","修改"等等),在设计时我改变ButtonType的值时让Text(继承自Button的属性)的值自动改变,比如我将ButtonType的值改成"新增",那么Text的值自动变成"新增",这一步已经实现了,问题是现在我手动将Text的值改成其它的值(任意值),然后运行,这也正常,然后再在设计时将ButtonType的值改成"修改",而运行后Text值还是刚才手工设置的值,不知道问题出在哪里?百思不得其解 ,希望大家帮助想想办法,万分感谢!
代码如下:
public class ButtonMX : System.Web.UI.WebControls.Button
{
public ButtonMX() : base()
{
}
private string _ButtonType;//仅仅为了说明问题,这里就不用枚举类型了
public string ButtonType
{
get
{
return _ButtonType;
} set
{
_ButtonType = value;
this.Text = value;
}
}
}
代码如下:
public class ButtonMX : System.Web.UI.WebControls.Button
{
public ButtonMX() : base()
{
}
private string _ButtonType;//仅仅为了说明问题,这里就不用枚举类型了
public string ButtonType
{
get
{
return _ButtonType;
} set
{
_ButtonType = value;
this.Text = value;
}
}
}
解决方案 »
- 我的gridview是分页的,但是我想把gridview中的数据插入到数据库中,怎么实现?
- asp.net的事件处理函数默认访问为什么是 protected 和 Private?
- 求一正则 替换空格
- 有点难度,如何给后台 动态添加的按钮 添加服务器端事件??????
- Nhibernate的数据访问(MS及Oracle)
- 关于表现层和数据层 进者有分
- 如果实现点击链接通过服务器端打开新窗口,但是又不会被3721等软件屏蔽呢?
- 求一树形结构源代码,要求无限级,类资源管理器。要以从数据库里取数据,谢谢!
- 请大家看看这段代码哪里写错了? 谢谢!
- VS2013调试 JS,用IE怎么突然不进入断点了,Why???
- 运行时DataGrid中某列标题不能正常显示,求救!!
- 为什么大家都不理我的贴子呀?关于BS系统框架的问题!!
like below: public string ButtonType
{
get
{
return _ButtonType;
} set
{
_ButtonType = value;
}
} public String Text
{
get
{
return _ButtonType;
}
set
{
_ButtonType = value;
}
}
public class ButtonMX : System.Web.UI.WebControls.Button
{.....protected override void Render(HtmlTextWriter writer)
{
if (_ButtonType != null && _ButtonType != String.Empty)
this.Text = _ButtonType; base.Render(writer);
}
{
base.CreateChildControls ();
this.Text = buttonType.ToString();
}
private SettingsType buttonType = SettingsType.新增;
public SettingsType ButtonType
{
get{
return buttonType;
}
set{
buttonType = value;
}
}
public enum SettingsType
{
修改,
新增,
查询
}
using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.ComponentModel;namespace MyControls
{ public enum SettingsType
{
不变=0,
修改,
新增,
查询
} /// <summary>
/// Summary description for ButtonMX.
/// </summary>
[DefaultProperty("Text"),
ToolboxData("<{0}:ButtonMX runat=server></{0}:ButtonMX>")]
public class ButtonMX : System.Web.UI.WebControls.Button
{
public ButtonMX() : base()
{
}
private SettingsType _ButtonType = SettingsType.不变;
public SettingsType ButtonType
{
get
{
return _ButtonType;
} set
{
_ButtonType = value;
this.Text = _ButtonType.ToString();
}
} protected override void Render(HtmlTextWriter writer)
{
if (_ButtonType != SettingsType.不变)
this.Text = _ButtonType.ToString(); base.Render(writer);
} }
}WebForm.aspx:
<%@ Register TagPrefix="cc1" Namespace="MyControls" Assembly="MyControls" %>
<form id="WebForm5" method="post" runat="server">
<cc1:ButtonMX id="ButtonMX1" style="Z-INDEX: 101; LEFT: 141px; POSITION: absolute; TOP: 89px" runat="server" ButtonType="修改" Text="修改fgdgfdgsgsfgsfgd"></cc1:ButtonMX>
</form>
但是,我希望Text的值可以通过手工更改,你的代码不能通过手工修改Text的值了我再说一下我的意思吧:通过改变ButtonType的值,Text自动变成ButtonType的值,Text的值也可以手动设置(也就是ButtonType中有一项是“自定义”),手动设置后,我再改变ButtonType的值后Text的值还是跟着变(除非选择的是“自定义”),这一切都是为了让控件在设计时更加方便。
我的意思就是这样,但问题是,(我最初的代码)如果手工改了Text的值,再去更改ButtonType的值,Text的值就不会跟着变了(运行一下就看出来了)希望大家再帮我看看,这个问题对我来说非常重要。
非常感谢所有关注的朋友。
public SettingsType ButtonType
{
get
{
return _ButtonType;
} set
{
_ButtonType = value;
if (_ButtonType != SettingsType.不变)
this.Text = _ButtonType.ToString();
}
}
{
public enum SettingsType
{
自定义=0,
修改,
新增,
查询
} /// <summary>
/// Summary description for ButtonMX.
/// </summary>
[DefaultProperty("Text"),
ToolboxData("<{0}:ButtonMX runat=server></{0}:ButtonMX>")]
public class ButtonMX : System.Web.UI.WebControls.Button
{
public ButtonMX() : base()
{
}
private SettingsType _ButtonType = SettingsType.自定义;
public SettingsType ButtonType
{
get
{
return _ButtonType;
} set
{
_ButtonType = value;
if(_ButtonType != SettingsType.自定义)
this.Text = _ButtonType.ToString();
}
}
protected override void Render(HtmlTextWriter writer)
{
base.Render (writer);
}
}}
public SettingsType ButtonType
{
get
{
return _ButtonType;
} set
{
_ButtonType = value;
if (_ButtonType != SettingsType.不变)
this.Text = _ButtonType.ToString();
}
}
this.ButtonMX1.ButtonType = csLig.SettingsType.不变;
this.ButtonMX1.ButtonType = MyControls.SettingsType.不变;