欢迎光临
我们一直在努力

将复合控件子控件事件上传到顶层的例子将复合控件子控件事件上传到顶层的例子-.NET教程,Asp.Net开发

建站超值云服务器,限时71元/月

这是一个选择省份然后将点击事件上传到控件顶层在页面处理事件的一个例子。加粗部分是整个上传事件过程。上传事件(暴露事件)、暴露属性、复杂属性管理、样式管理等是asp.net服务器自定义控件的高级主题。

using system;

using system.web;

using system.web.ui;

using system.data;

using system.data.sqlclient;

using system.web.ui.webcontrols;

using system.componentmodel;

using yeno.enbiz.news.tools;

namespace yeno.enbiz.news.controls

{

/// <summary>

/// researchctrl 的摘要说明。

/// </summary>

[toolboxdata("<{0}:localctrl_province runat=server></{0}:localctrl_province>")]

public class localctrl_province : system.web.ui.webcontrols.webcontrol,inamingcontainer

{

private tablecell _province;

public event commandeventhandler clickprovince;

/// <summary>

/// 将此控件呈现给指定的输出参数。

/// </summary>

/// <param name="output"> 要写出到的 html 编写器 </param>

protected override void render(htmltextwriter writer)

{

addattributestorender(writer);

writer.addattribute(htmltextwriterattribute.cellpadding,"5",false);

writer.addattribute(htmltextwriterattribute.cellspacing,"0",false);

writer.addattribute(htmltextwriterattribute.width,"100%",false);

writer.renderbegintag(htmltextwritertag.table);

writer.renderbegintag(htmltextwritertag.tr);

_province.rendercontrol(writer);

writer.renderendtag();

writer.renderendtag();

}

protected override void createchildcontrols()

{

if(!page.ispostback)

{

controls.clear();

clearchildviewstate();

}

_province=new tablecell();

createprovince();

this.controls.add(_province);

}

protected void createprovince()

{

datatable dtb=(datatable)datacall.runsqlsp("n_province_getall",returntype.executereader);

for(int i=0;i<dtb.rows.count;i++)

{

linkbutton lb=new linkbutton();

lb.text=dtb.rows[i]["province"].tostring().trim();

lb.causesvalidation=false;

lb.commandargument=dtb.rows[i]["id"].tostring();

lb.command +=new commandeventhandler(province_command);

_province.controls.add(lb);

_province.controls.add(new literalcontrol("&nbsp;"));

}

dtb.dispose();

}

protected void province_command(object sender,commandeventargs e)

{

onclickprovince(e);

}

protected void onclickprovince(commandeventargs e)

{

if(clickprovince!=null)

{

clickprovince(this,e);

}

}

}

}

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » 将复合控件子控件事件上传到顶层的例子将复合控件子控件事件上传到顶层的例子-.NET教程,Asp.Net开发
分享到: 更多 (0)