In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-22 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
Editor to share with you the example analysis of ASP.NET control ID, I believe that most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!
ASP.NET control ID
I often see people say not to use dynamic controls in ASP.NET. I think the main reason is that using dynamic controls will bring some problems. In the process of doing a project, I will always make a small summary caused by dynamic loading controls.
1. After loading the control using LoadControl, some controls in the user control no longer respond to events.
This problem is mainly caused by loading the control inside the if (! Page.IsPostBack) and leaving it outside. This problem is explained in detail on the blog of thinking and returning.
2. There is a problem with the response of some controls in the user control, for example, the CLICK event is not triggered when a button is selected for * times, and the second time is fine.
This is due to the fact that ID is not set for the control, and the role of the control ID is described in detail below. Such as
Control userControl= (Control) Page.LoadControl ("Test.ascx"); userControl.ID= "Test"; AddControl (userControl)
3. If the user control includes a DataGrid control, there may be a problem of not responding to the DataGrid event after the control is loaded.
This is like a bug, and the loaded control must be cast, such as:
Test userControl= (Test) Page.LoadControl ("Test.ascx")
Note: the Test type is used above, not Control!
I have mentioned this issue in previous Blog, and this approach will reduce the scalability of the system. I have a solution that I can discuss with you (using the strategic model):
Public class BaseControl: System.Web.UI.UserControl {public virtual BaseControl ProcessThisControl ();}
All user controls inherit from BaseControl, if there is a Datagrid control, by the overide ProcessThisControl method, such as: return this as Test
Load the control as follows:
BaseControl userControl= (BaseControl) Page.LoadControl ("Test.ascx"); userControl.ProcessThisControl ()
4. How to use JavaScript in user control.
As we all know, using client-side scripts will greatly improve the response speed of the page, while avoiding frequent page refreshes. So it's a good way to use javascript to implement partial control in the page, but what about accessing a child control in a user control?
The mode of use is as follows:
Document.all..disabled=true
/ / set TestControl to unavailable
Page.RegisterStartupScript ("OnInitControl", "
Document.all.Test_TestControl.disabled=true; ")
/ / Test is the user control, and TestControl is the child control in the user control.
Now let's talk about the ASP.NET control ID. When you access the aspx file, IIS compiles the script for aspx. When compiling, the contents of the user control are written on the same page. In order to prevent the control in the page from being the same as the control in the user control, the name of the control in the user control is modified to: user control name: child control, and the ASP.NET control ID is modified to the user control ID_ child control ID. When dynamically loading a control, if you do not assign a value to the ID of the control, the ASP.NET control ID is the last loaded control ID, so you should set ID.
The above is all the content of this article "sample Analysis of ASP.NET Control ID". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.