asp.net dynamic load user control, about the background add, modify the thinking _ practical skills

Source: Internet
Author: User
Look below this typical background (rough):

To tell you the truth, I am tired of using the. aspx file, such as "Friendship link" This module, there will be "Add Friendship link" "Modify Friendship Connection" "Friendship Connection list", simple words, you can "add" "modify" to synthesize a file. Each time you create an. aspx file. My idea now is to use the "user Control + configuration file" to implement, although the number of files may not be much less. But in the programming to a certain extent, I think we will have the same idea.

The first thing to involve is the dynamic addition of the user control, which can be dynamically loaded according to the parameters, as follows:
Copy Code code as follows:

protected control control;
protected void Page_Load (object sender, EventArgs e)
{

by Ahuinan 2009-4-18
int id = Convert.ToInt32 (request.querystring["id"]);
Switch (ID)
{
Case 0://do not load user controls
Response.Write ("You did not load any controls");
Break
Case 1://Load User control
Control = Page.LoadControl ("~/login.ascx");
Control.id = "uc1";//This is named in order to get the value of the inside control.
PlaceHolder1. Controls.Add (Control);
Break
Default
Break
}
}

Instead, you need only one. aspx file, and there is a user control in the file, and the code is as follows:
Copy Code code as follows:

<asp:placeholder runat= "Server" id= "PlaceHolder1" ></asp:placeholder>

If you have a textbox with the id "tbxusername" in this "user control", in the. aspx file, to get this value, the code is as follows:
Copy Code code as follows:

((TextBox) placeholder1. FindControl ("uc1"). FindControl ("Tbxusername")). Text

Here is simple to say my idea, to cooperate with the http://www.jb51.net/article/17829.htm I said before this article implements a class that inherits from page, writing code that dynamically loads the user control. You need to work with a configuration file so that the left menu and dynamically loaded controls can be uniformly handled in the configuration file. The idea is very clear, but the writing is a bit messy, hope to have this thinking friend and I exchange, recently and a few friends chatted, but did not have such an idea.

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.