To upload a composite control child control event to the top example of a composite Control child control event upload to the top level

Source: Internet
Author: User
Tags tostring
Control | Upload This is an example of selecting a province and then uploading the click event to the top level of the control in the page handling event. The bold part is the entire upload event process. Upload events (exposure events), exposure attributes, complex property management, style management, and so on are advanced topics for ASP.net server custom controls.
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>
Summary description of the 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>
Renders this control to the specified output parameter.
</summary>
<param name= "Output" > HTML writer to write </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&LT;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 (""));
}
DtB. Dispose ();
}
protected void Province_command (Object Sender,commandeventargs e)
{
Onclickprovince (e);
}
protected void Onclickprovince (CommandEventArgs e)
{
if (clickprovince!=null)
{
Clickprovince (this,e);
}
}
}
}





Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.