Summary of some problems when streaming controls in ASP.NET

xiaoxiao2021-03-06  67

I often see that some people say that do not use dynamic controls in ASP.NET, I think the main reason is that the use of dynamic controls will bring some problems. In the process of doing projects, I will always be triggered by dynamic loading controls. Small summary.

1 ,

After using the LoadControl load control, some of the controls in the user control no longer respond to the event.

This problem is mainly caused by loading controls within IF (! Page.ispostback), and placed outside. in

This issue has been described in detail on the blog of Site.

2,

There is a problem with some controls in the user control. If a button is selected for the first time, the Click event is not triggered, the second time.

This is because the control ID is not caused by setting the ID, the control ID is described in detail below. Such as

Control UserControl = (Control) Page.loadControl ("Test.ascx");

UserControl.id = "test"; addControl (UserControl);

3. If you include a DataGrid control in the user control, you may have problems with the DataGrid event after loading the control. This seems to be a bug, you must enforce the loaded control, such as test userControl = (TEST) Page.loadControl ("Test.ascx"); Note: Top Test Type, not Control! I am This problem has been mentioned in the previous blog, which will reduce the scalability of the system. I have a solution that can be discussed with everyone (using policy mode): public class basecontrol: system.Web.ui.userControl {public virtual basecontrol processthisControl ();} Inherited from BaseControl, if there is a DataGrid control, by Overide ProcessThisControl method, such as: Return this as test; load controls as follows:

BaseControl UserControl = (BaseControl) Page.loadControl ("Test.ascx"); UserControl.ProcessThisControl ();

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

New Post(0)