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

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

Using Nested User Controls

Posted By:      Posted Date: April 10, 2011    Points: 0   Category :Windows Application

Hi everybody,

I have an issue  with  nested  User Control, I hope someone  may  help  to  work it out.

I have a  class library  solution  with  one  user control   and  some  nested  controls  inside it.  this is  the code:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.ComponentModel.Design;
using System.Windows.Forms.Design;

namespace myBaseAssembly
  public partial class BaseControl : UserControl
    public BaseControl()


View Complete Post

More Related Resource Links

nested user controls



i have two usercontrols say usrcntrl1.ascx and usrcntrl2.ascx. In usrcntrl2, i have just few links defined. And I want this usrcntrl2 to show up in every page just like header. And now i have usrcntrl1 to call usrcntrl2 on the page_load. How to use nested usercontrols in this case? Is it possible ?

UI Datepicker and web user controls



I have developed an application using the Master-Detail pattern described in this Matt Berseth article.

The only difference between Matt's article and me is that I am using a FormView object in place of a DetailsView.

Everything works fine except that the formview object, in my case it's inside a user control and I can't figure out how to use the jquery datepicker UI plugin.

I have tried to put the script block for the datepicker either in the aspx page as well as inside the user control but in both cases the calendar does not come up when the related textbox get the focus.

Any suggestion on how to work with the datepicker inside an ascx?

thanks in advance!

Toolbox: User-Friendly UIs, Online Data Entry Controls, and More


Microsoft® Office is one of the most well-known and most-used consumer products. For many people, their only experience with a computer is when using Office, be it checking e-mail, creating presentations, or writing a document.

Scott Mitchell

MSDN Magazine February 2006

ASP.NET 2.0: Personalize Your Portal with User Controls and Custom Web Parts


ASP.NET 2.0 introduces a Web Part control that is designed to deal with the serialization, storage, and retrieval of customization and personalization data behind the scenes. In this article, the authors explain how you can put the WebPart control to work in your ASP.NET 2.0 applications.

Ted Pattison and Fritz Onion

MSDN Magazine September 2005

Advanced Basics: Adding New Features with User Controls


In past versions of Visual Basic, there were rudimentary graphics controls. In Visual Basic .NET you have the GDI+ library, which enables you to draw lines, circles, and most anything else. But how can you use the functionality of GDI+ to create lines and other graphics that respond to user mouse clicks and events? Find out.

Ken Spencer

MSDN Magazine June 2003

Windows Forms: Developing Compelling User Controls that Target Forms in the .NET Framework


In the beginning, writing controls meant dealing with Windows messages. Then came Visual Basic controls, which introduced methods, properties, and events. Later, ActiveX controls, which ran atop COM, became popular. While each innovation in control writing brought more flexibility, nothing has matched the versatility of the new .NET Windows Forms controls and Web Forms controls. This article, the first of a two-part series, introduces the reader to Windows Forms, beginning with their inheritance from one of the .NET CLR base classes, which makes control creation much faster than before. Control programming is illustrated through the development of a login control. The equally flexible Web Forms controls will be covered in Part 2.

David S. Platt

MSDN Magazine April 2002

asynchronous loading user controls


I have 3 user controls that I have to load at the same time.  They each contain a gridview that pulls data from the database.  They are doing a "delay" load of the data so there is a progress bar template that shows that the data is loading however the first gridview fires and loads, then the second, then the third and I need them to all fire at the same time.  Any ideas? 

User Controls and Control Extenders


Two separate questions, but sufficiently intertwined that I'm going to try the two together....

Firstly - User Controls and Behaviours

I have a User Control which contains a few visual controls.  I am attaching some behaviours by using GetScriptDescriptors and am passing some JavaScript to the browser using GetScriptReferences.  That is all rock solid and working well.  However, when developing, I did discover that I couldn't attach the behaviours to the User Control itself - not surprising as rendering a User Control does not create a DOM element which represents the actual control.  So, I have attached my behaviours to a "random" TextBox within the User Control. 

So - first question, is there a better way to do that?  For example, should I always be rendering a SPAN as an element to surround the control?  Not sure what that would do to the robustness of the rendering.  What is the right way to attach a behaviour to a User Control.

Secondly - Accessing those same Behaviours later

Assume I have placed a User Control on the page.  That User Control exposes a Property (actually a Javascript Function of course) which does "something" to the control - for the sake of example we'll say that the function is set_Border(colour). 

How to dynamically create user controls ?



can you explain how to create user control dynamically in a web form ?When i am creating server controls of user controls are not instantiated and it is not getting initialized .when i am tyying to initialize its properties error occurs tha object instance not created .

Any suggestion ? 

How to add user controls into toolbox?

Hello, I have created a user control with ComboBox  & TreeView together. I want to use this control as a component so that I can drag and drop this control to other windows form! So what are the steps to get user control into toolbox? THANKS!

How to pass param between two user controls?

Hello,I would like to convert some aspx code in user controls. This would lead me to having a master user control that contains other controls inside.The contained user controls have datasource with some control parameters that takes the value from a control present in the aspx (now) and that will then moved in the container user control.which is the best way to handle a scenario like this?thanks a lot

Nested controls in UserControl return null (FindControl)

Hi everyone, I have a very weird issue. I have a UserControl that has some controls inside. I want to refer those controls after, in another postback. But when I try to get them the ".Controls" property of my controls returns null. I'm working on vs2008 Here is the sample code: public partial class MyUserControl : System.Web.UI.UserControl { protected void Page_Load(object sender, EventArgs e) { foreach (Control control in this.Controls) { Response.Write(control.ClientID); } } private void MyTable() { Table table = new Table(); TableRow row = new TableRow(); TableCell cell = new TableCell(); CheckBox check = new CheckBox(); check.ID = "theId"; check.Text = "My Check"; check.AutoPostBack = true; cell.Controls.Add(check); row.Cells.Add(cell); check = new CheckBox(); check.ID = "theOther"; check.AutoPostBack = true; check.Text = "My Other Check"; cell = new TableCell(); cell.Controls.Add(check); row.Cells.Add(cell); table.Rows.Add(row); this.Controls.Add(table); } protected override void Render(HtmlTextWriter writer) { MyTable(); base.Render(writer); } } And in the Default.aspx is like:<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.cs" Inherits="Tester.Default" %> &

Tab Container, Tab panels with User Controls - bug?

Hello all, I have a aspx page with a tab container, and 5 tabs on it - 4 of which hold user controls on them. I have a strange issue that presents sometimes, and I am not sure just what is causing it. Here is the scenario : there is one user control on each tab. On each of those user controls, there are a number of radio buttons in Update Panels. If a user selects one of the tabs, then selects another tab and clicks on one of the radio buttons on that tab causing a postback, when the page refreshes, the content of the previous tab becomes visible at the top of the current tab, pushing the original content down below it - as if the content of the previous tab has been appended to the top of the current tab's content. Has anyone out there experienced anything like this? What I did to "fix" the issue was simply to go into the aspx code for the tab container, and change the order of the tab panels in the code, something like this :  <cc1:TabContainer ID="tabContainer" runat="server"> <cc1:TabPanel ID="tabFirstTab" runat="server" HeaderText="My first tab" > <ContentTemplate> <uc1:usercontrol1 ID="UC1" runat="server" /> </ContentTemplate> </cc1:TabPanel>

Dynamically adding User Controls -- newbie question!

I am new to ASP.NET (coming from ColdFusion, thank goodness I'm away from that!).  And I am have THE hardest time understanding how to work with forms in ASP.NET.  Here's what I am doing:Dynamically add User Controls to a PlaceHolder based on some int value (which currently is passed in a HiddenField).Fire an event if the WebControls inside of the User Control change, then handle that event in the Main Page (i.e. save the input to DB)When the user clicks the "Next/Continue" button, the next controls for the next page are loaded.And I guess maybe I just can't seem to get how things work in ASP.NET, because I am really struggling with the general idea of how ASP.NET flows.  Should I be dynamically loading the controls in Page_Init, or Page_Load?  Or should I load the controls when the buttonclick event is fired?Do I have to add the axCtrl.OnDataChange += new EventHandler(HandleAxControlDataChange); line on Page_Load?  Or should I put this in When I first load the UserControl, I need to initialize some WebControls within the UserContorl.  Is there a way to know if I have loaded new user controls into my placeholder?  I can't use Page.IsPostback, because after the first page, every page is a postback from the buttonclick.Any help for this confused newbie would be GREATLY appreciated!!Here's what I have: pu

Issue accessing textbox controls nested within a DetailsView within an UpdatePanel

I have a couple of textboxes nested with a detailsview, within an updatepanel.  When I try and access them from the code behind, it returns a null value as if they don't exist.  Can't figure out why that would be.ASPX code is: <asp:UpdatePanel ID="upSpecificShout" runat="server" UpdateMode="Conditional" ChildrenAsTriggers="true" > <ContentTemplate> <asp:DetailsView ID="dvSingleShout" DataSourceID="sdsSingleShout" runat="server" AutoGenerateRows="false" OnDataBound="SetDVIcons" HeaderStyle-CssClass="noDisplay" > <EmptyDataTemplate> <p class="Watermark"> The panel on the left shows a list of everything you've shouted. (Your replies to other shouts are highlighted in blue/green.) </p> <p class="Watermark"> This right hand panel will show specific shouts with a list of replies etc.. Just do a little click on a shout title to display more detail here. </p> <p class="Watermark">

Problem with user controls and the toolbox

Im building a control library, its just a library that builds to a dll with a bunch of user controls. But So far I can only get "user controls" to be loaded into the toolbox in a separate project. Many on my user controls need only be derived from a specific control and I often find using a user control is unnecessary for the control. So the question is, how can I get a control that is not derived from the user control class, to show in the toolbox, in a separate project? Another thing I would like to decorate my controls with an icon for the toolbox. I tried [ToolboxBitmap("Filename")] at the top of the class but it did not work for me.AbleOpus.ath.cx

Accessing a public property of a nested user control in a master page from a pages' user control

Hi  I've got a web site that has a master page and that master page (mpMaster that has a user control (ucControl1) which has a sub user control (ucControl2), this user control has a property which accepts a value. Now, I have a page that uses the master page and on this page I have another user control (ucPageControl), I need to  find a way of setting the value in ucControl2 from ucPageControl. Is this possible at all? Many thanks Ed
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

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