Dynamically load the components of the user control! (four)

xiaoxiao2021-03-06  100

(It is very lazy, the content of the dynamic loading user control is really written, said that it is not finished. It is related to everything in ASP.NET!)

We have to do ASPX leaves without associated CS files. In fact, the leaves of the leaves are not on ASPX, but on ASCX. The role from ASPX is just an entry. References to components, and components can manage many ASCX pages, so-called leaf surface ASCX leaves should also be the foliar of CS.

So all things throughout the system are in the component, and the ASPX is a simple access entry, and ASCX is something on the pure page. The ASPX portal calling component, the component calls the ASCX page and the interaction of the corresponding customer.

Only in this way can we separate each worker and background.

You can have a team to develop pages (pure pages don't need any CS code, all ASCX), and another team to develop components. Finally, the assembly is the entire system, and the component is called by the ASPX.

Let's make a unciphered ASCX leaf, there is a button on the folia, then write a component to load this ASCX leaf, and how to respond to this button!

(Taking nonsense, writing articles sometimes is a very painful thing!) ASCX leaves and the background code to handle the leaves is a very good thing. I don't know if you find that a foliage can only Associate with a background code file, it is impossible to have two classes to associate this leaf. With components to load ASCX and corresponding events, you can use the same folio ASCX to have many different components. It can be reused. Not only is reused in the same project, but it is necessary to use it.

Examples:

For the ASCX page that is unconnected CS file. There is a Button. ID is MyButton. Of course, we can find him in the component! ASCX leaves can also be a text file. Change the suffix name to ASCX.

Loadskin written in front of me! Then it is possible to handle the Button's onclick event.

Then quote this component in ASPX. Of course, it can also be referenced in ASCX and is an effect.

ASCX is named A.ASCX. There is only one button above

Also inherited SkinnedControl

Namespace region.controls {

///

// / Load user components, load different components

///

Public class abutton: SkinnedControl {

Button bt;

Public Abutton (): Base ()

{

Base.skinpath = "a.ascx";

}

///

/// Initialize the formation of a touchpad, perform the necessary dynamic settings or updates

///

Override protected void initializeskin (Control Skin) {

Bt = (Button) Skin.FindControl ("MyButton");

Bt.Click = New EventHandler (BT_Click);

Skin.DATABIND ();

}

///

/// Get the component

///

Public override controlcollation controls {

Get {

EnsureChildControls ();

Return Base.Controls;

}

}

Private Void BT_Click (Object Sender, Eventargs E)

{

bt.text = "Heart Rain Building";

}

}

I am like writing the same component called EBUTTON Root Abutton.

Change the event to bt.text = "Heart Rainstall !!!!!!!!";

Let's take a look at what is like a codeless ASPX!

This looks like this:

This is the case after clicking:

Different things are different.

Last

(

continued

)

转载请注明原文地址:https://www.9cbs.com/read-123599.html

New Post(0)