.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal

Home >> Interview Question >> ASP.Net >> Post New Question Subscribe to Interview Questions

How to create an instance of a user control programmatically in the code behind file of a Web Forms page

Posted By :Syed Shakeer Hussain     Posted Date :August 22, 2010    Points :10   Category :ASP.Net 
Create a new Web Forms page in Visual Studio.
Navigate to the code behind file generated for this Web Forms page.
In the Page_Load event of the Page class, write the following code.
// Load the control by calling LoadControl on the page class.
Control c1 = LoadControl("test.ascx");

// Add the loaded control in the page controls collection.

You can also find related Interview Question to How to create an instance of a user control programmatically in the code behind file of a Web Forms page  below: 

How to use a user control in a Web Forms page

Declare the @ Register directive.

For example, use the following code.
<%@ Register TagPrefix="UC" TagName="TestControl" Src="test.ascx" %>

What is Private Constructor? and it's use? Can you create instance of a class which has Private Constructor?

When a class declares only private instance constructors, it is not possible for classes outside the program to derive from the class or to directly create instances of it. (Except Nested classes)
Make a constructor private if:

1) You want it to be available only to the class itself. For example, you might have a special constructor used only in the implementation of your class' Clone method.

2) You do not want instances of your component to be created. For example, you may have a class containing nothing but Shared utility functions, and no instance data. Creating instances of the class would waste memory. (More...)

What are the requirements to create a CLR based user-defined type?

CLR must be enabled for the instance and A class created with a CLR-compatible language. (More...)

What is a user control?

An ASP.NET user control is a group of one or more server controls or static HTML elements that encapsulate a piece of functionality. A user control could simply be an extension of the functionality of an existing server control(s) (such as an image control that can be rotated or a calendar control that stores the date in a text box). Or, it could consist of several elements that work and interact together to get a job done (such as several controls grouped together that gather information about a user's previous work experience). (More...)

What is different between Web User Control and in Web Custom Control?

Web user controls : Web User Control is Easier to create and another thing is that its support is limited for users who use a visual design tool one gud thing is that its contains static layout one more thing a seprate copy is required for each application.

Web custom controls: Web Custom Control is typical to create and gud for dynamic layout and another thing is it have full tool support for user and a single copy of control is required because it is placed in Global Assembly cache. (More...)

How u can create XML file?

To write Dataset Contents out to disk as an XML file use:
MyDataset.WriteXML(server.MapPath("MyXMLFile.xml")) (More...)

How you will Hide Column(s) in the Windows Forms DataGridView Control?

Set the DataGridViewColumn.Visible property to false.

dataGridView1.Columns("CustomerID").Visible = False

dataGridView1.Columns["CustomerID"].Visible = False; (More...)

Is view state lost if a user refreshes a Web page? What if the user copies the URL and open it in other browser?

View state is maintained within a page's HTML, so it is lost if a page is refreshed or if the URL is copied. (More...)

What can you do to make a Web page more useful to a user who does not use a mouse?

There are number of things which can be done so that Site can be accessed without a mouse.

1.Provided access keys for all the controls.You can use access keys for Web controls using AccessKey property.
2. Define Logical Tab order.
3. Specify default button on the form.
4. Set default focus on the form in a logical location where data entry normally begins. (More...)

How to start NotePad file in AsP.NET with code ?

System.Diagnostics.Process.Start("Notepad.exe"); (More...)

Quick Links For Interview Questions Categories:
ASP.Net Windows Application   .NET Framework   C#   VB.Net   ADO.Net  
Sql Server   SharePoint   Silverlight   OOPs   JQuery   JavaScript/VBScript
Biztalk Patten/Practices .IIS WCF WPF WWF
Networking Aptitude Others   All      

Find questions, FAQ's and their answers related to .NET, C#, Vb.Net, Sql Server and many more.

Now you can find lots of .NET, C#, Vb.Net, SQL Server,Windows, ASP.Net related Questions and their Answers here at www.dotnetspark.com. Our aim is to help you pass your certification Exams (MCP, MCSD, MCAD etc.,) with flying scores and get good name in your company.

So, Start looking our Interview Question section daily and improve your .NET Skills. You can also help others by posting Interview Questions and their Answers in this section.

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend