c# - Difference between a WebControl and a CompositeControl? -


I'm looking around the web and got some articles about the subject, but I still do not understand the difference Between them I have the code shown, if I get it from the composite control, it works perfectly, but if I do not deprive of WebControl (they both present the code, but only handles the compositing control event)

  using the system; Using System.Web.UI; Using System.Web.UI.WebControls; Namespace Test Library {Public class template control: composite control (text box; txtName = new text box); Text box txtEmail = new text box (); Button btnSend = new button (); Private Zero Setwels () {btnSend.Text = "Skicka"; } Protected override zero CreateChildControls () {SetValues ​​(); this. Control. Add (New Little Control ("Nunn:")); This.Controls.Add (txtName); this. Control. Add (New Little Control ("& lt; br / & gt;")); this. Control. Add (New Little Control ("Email:")); This.Controls.Add (txtEmail); this. Control. Add (New Little Control ("& lt; br / & gt;")); BtnSend.Command + = New CommandEventHandler (btnSend_Command); This.Controls.Add (btnSend); } Zero btnSend_Command (Object Sender, CommandEventArgs e) {this.Page.Response.Write ("skicka-knappen on two nuclitts! 


& gt; }}}

So when I click the button and the control is provided as a WebControl, then nothing happens but if I change the WebControl to composite control, The text is printed. Why? What is the difference between WebControl and Composite Control?

composite control apply ININGContainer while < Code> WebControls no

There are more differences between the two, but this is the reason that the overall control can root the event to its child on the web, you can not control it by changing the declaration of your class:

  Public category TemplateControl: WebControl, InamingContainer  

Voice, your button event will now be controlled!

There is only one marker interface that ASP.NET Tells the fact that there are such children in control that can be reached independently from the control of their parents, so the child receives those extra-beautiful IDs that we know and love the ASP.Net developers and (eg, Code> ctl00 $ ctl00 ).

If the WebControl does not apply to ININGContainer , then the child's ID is not guaranteed to be unique, so parents recognize it credibly Can not and can not move events forward.


Comments

Popular posts from this blog

asp.net - Javascript/DOM Why is does my form not support submit()? -

sockets - Delphi: TTcpServer, connection reset when reading -

javascript - Classic ASP "ExecuteGlobal" statement acting differently on two servers -