Dynamic control, coding generation process, mysterious Container variable

xiaoxiao2021-03-06  72

These days have a few people asking similar questions, "Dynamic loading controls, why can't the control event not trigger?", The problem is that they are all

if (! ispostback) {// Dynamic Generation or Load Control / / Perhaps the Connection Control Event Processing Function / / Add to the Controls} of the Parent Control

Generate or load dynamic controls. When the control triggered, postback to the server side, ISPOSTBACK == True, these controls are not regenerated, how can I trigger an event? So the answer is that when you need to dynamically generate or load the control, you should do it outside of if (! Ispostback). I ask why I want to do it within if (! Ispostback)? The answer is that I want to generate it once, just like the ASPX page.

#% &% # &% ^ # &, How can you think this control only once? These stations are not magic, want to generate a Button object, you need to use

Button btn = new button ();

Need to trigger its Click event, you need to use

Btn.click = new EventHandler (YourHandler);

Even icon contains

The page, it is also converted into a C # or VB file, compiled into assembly, then execute it.

Do not believe? Add a page, TestControls.aspx:

<% @ Page debug = "true"%> <% @ import name "%> <% @ import namespace =" system.data.sqlclient "%>

<% # DataBinder.Eval (Container.DataItem," Name ")%> < / asp: templateColumn>