自定义控件加事件
来源:互联网 发布:淘宝助理旧版本下载 编辑:程序博客网 时间:2024/06/05 16:37
作用:当自定义控件的下拉发生变化时,其他控件或HTML代码做相应的业务处理。
一、自定义控件的HTML代码:
.....................
.....
<asp:DropDownList ID="ddl_ProfileType" Width="200px" runat="server" AutoPostBack="true"
OnSelectedIndexChanged="ddl_ProfileType_SelectedIndexChanged">
</asp:DropDownList>
......
..................
当下拉发生变化时,触发一个事件。
二、自定义控件的CS代码:
public partial class AddProfile : System.Web.UI.UserControl
{
public event EventHandler ChangeProfileType;
private void OnChangeProfileType(object sender,EventArgs e)
{
if (this.ChangeProfileType != null)
{
ChangeProfileType(this, e);
}
}
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
}
}
//機構類型
protected void ddl_ProfileType_SelectedIndexChanged(object sender, EventArgs e)
{
if (this.ddl_ProfileType.SelectedValue == ((int)ProfileType.Individual).ToString())
{
Create_ProfileTypeShow(true);
}
else
{
Create_ProfileTypeShow(false);
}
this.OnChangeProfileType(sender, e);
}
}
三、调用自定义控件的代码
public partial class Profile_Add : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
}
this.AddProfile1.ChangeProfileType += new EventHandler(AddProfile1_OnChangeProfileType);
}
void AddProfile1_OnChangeProfileType(object sender, EventArgs e)
{
ProfileORM ProfileModel = new ProfileORM();
ProfileModel = this.AddProfile1.GetProfileModel();
if (ProfileModel.ProfileType == (int)ProfileType.Individual)
{
this.tr_MediaIndivudual.Visible = true;
this.tr_MediaType.Visible = false;
}
else
{
this.tr_MediaIndivudual.Visible = false;
this.tr_MediaType.Visible = true;
}
}
}
注意:如果自定义控件放在Ajax里面,其他代码也要放在Ajax里面,才能看得出效果。
- 自定义控件加事件
- 给自定义组件加事件
- 用户控件自定义事件
- 控件的自定义事件
- 自定义控件的事件
- 自定义控件添加事件
- C#-控件-自定义事件
- 自定义控件添加事件
- 自定义控件添加事件
- 自定义控件添加事件
- Winform自定义控件事件
- .net 自定义控件事件
- 自定义控件触动事件
- C# 自定义控件,自定义属性,自定义事件
- 给自定义控件加个个性化图标
- GetPostBackEventReference加RaisePostBackEvent实现自定义控件中回调传参
- 重写panel控件,加自定义边框颜色
- 图片加文字的自定义控件
- 如何去掉Shopex前台与后台的版权标识
- Ubuntu中用VirtualBox虚拟机安装WinXP完整图解(一)
- GTD
- ExtJs自学教程(1):一切从API开始
- 回调函数中lpbyte的处理,ref byte与byte[]
- 自定义控件加事件
- shell if语句
- 介绍Linux下面线程的操作、多线程的同步和互斥
- linux convert图像处理命令
- General formula for calculating memory usage
- wait_on_bit_lock()使用示例
- ExtJs自学教程(2):从DOM看EXTJS
- 项目中常用的工具类
- IT职业规划之从开发人员到行业专家