How to dynamically load user controls using ASP. NET

Source: Internet
Author: User

Step 1: Put the user control in mylist. ascx, and the control command is: CopyCode The Code is as follows: <% @ Control Language = "C #" autoeventwireup = "true" codefile = "viewcomment. ascx. cs" inherits = "control_viewcomment" %>

At this time, you already have inherits, And the built-in classname is its name. If not, you must create the classname attribute.
Assume that it has a public property ID.
Step 2: UseCopy codeThe Code is as follows: <% @ reference control = "mylist. ascx" %>
<% @ Page Language = "C #" codefile = "getascx. aspx. cs" inherits = "adentity_getascx" %>
Reference. At this time, the ascx control can be dynamically loaded in the code page getascx. aspx. CS:
Control_viewcomment CTRL = (control_viewcomment) page. loadcontrol ("~ /Control/viewcomment. ascx ");
CTRL. ID = request ["adentityid"];
Base. Controls. Add (CTRL );

In addition:Copy codeThe Code is as follows: <% @ register Assembly = "business" namespace = "business" tagprefix = "my" %>

Complete.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.