.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

Finding UserControls within a PlaceHolder control

Posted By:      Posted Date: September 28, 2010    Points: 0   Category :ASP.Net


I am having problems finding my UserControls inside the Controls collection of a Placeholder control.  

I have a ListView control with a PlaceHolder control in its ItemTemplate. OnItemdataBound for the ListView control I am adding a custom UserControl to the Controls collection of the Placeholder control. It all renders fine. My problem is when I try to find my user controls in the Placeholder. I just can't get it back. My code is below.

My objective here is to get to the input controls within my UserControl and call the save method of this. Please help.

PlaceHolder intakeBenefitHolder = null;
protected void lvIntakeBenefits_ItemDataBound(object sender, ListViewItemEventArgs e)
 if (e.Item.ItemType == ListViewItemType.DataItem)
  using (ListViewDataItem item = (ListViewDataItem)e.Item)
   // cast the ListViewDataItem to a Benefit
   Benefit benefit = (Benefit)item.DataItem;
   // create the ClientIntakeBenefitDictionary dictionary for the benefit and add it to the BenefitAtIntake control
   ClientIntakeBenefitDictionary dictionary = new ClientIntakeBenefitDictionary(benefit, new Guid(this.ContactId));

   // Create the IntakeBenefit

View Complete Post

More Related Resource Links

Finding a control from a control collection



I'm trying to write a bit of code that will format all the numeric values in lables in my gridview. here's what i am doing right now:

On the RowDataBound Event, i create a row object for the row that is currently being bound.
then i go use the FindControl method to grab each label by name.

Problem is there's too many columns in this table and i really dont wnat to have to type it all out. Here's an example of what i am currently doing

' Get row being bound
Dim myRow = e.Row

' Get labes to be formatted
Dim lblMunicipalIncineration = CType(myRow.FindControl("lblMunicipalIncineration"), Label)

' format labels
If lblMunicipalIncineration IsNot Nothing Then
    If Not String.IsNullOrEmpty(lblMunicipalIncineration.Text) Then
        lblMunicipalIncineration.Text = FormatNumber(lblMunicipalIncineration.Text, 0, TriState.False, TriState.False, TriState.True)
    End If
End If

Can i use myRow.Controls to grab a list of all the controls and then somehow get a list of all labels in the collection and then use a for loop to go through and format each label?

Finding a WPF control by Name in a Panel

How can I loop through the controls collection of a WPF panel and find a control by name?  The StackPanel1.Children(0).Name property does not exist. I looking for a method equivelent to this WinForm code... Friend Function DBX_FindControlByName(ByRef objContainer As Object, _   ByVal strControlName As String, _   ByRef objFoundControl As Control) As Boolean   Dim objControl As Control = Nothing   If Not IsNothing(objFoundControl) Then Return True   Try   'objContainer must be a controls collection like Me.Controls   For Each objControl In CType(objContainer, Control.ControlCollection)   If objControl.Name.ToUpper = strControlName.ToUpper Then objFoundControl = objControl   Exit For   Else   If objControl.HasChildren Then   'This control has children so it must be a container DBX_FindControlByName(objControl.Controls, strControlName, objFoundControl)   End If   End If   Next   Return True   Catch ex As Exception strErrMsg = "DBX_FindControlByName." & objControl.Name & ": " & ex.Message   End Try   End Function Thanks. Mike

LoginView.FindControl not finding control

I'm trying to bind data to a repeater. The repeater is inside a loginView control. Like so:            <asp:loginview id="loginView" runat="server">                <anonymoustemplate>                    <asp:repeater id="rpLessons" runat="server">                                            <itemtemplate>                            <div>                                <a  href="Default.aspx?lid=<%# Eval("PodID") %>"><%# Eval("Name") %></a><%#Eval("Duration")%>                            </div>                        </itemtemplate>    &n

Finding a control inside a ListView on a master page

I have a listview on a master page that ISN'T part of a content place holder that I want to fill in and disable if the user is already logged in. I have a label set up already which works fine. I'm just having problems accessing a Textbox by the name of "NameTextBox" in the InsertItem template of the listview.Here is the part of my codefile:Dim vCurrentUser As MembershipUser = Membership.GetUser() If Not vCurrentUser Is Nothing Then Dim pnl As Label = LoginView1.FindControl("Label1") pnl.Text = Page.User.Identity.Name Dim NameBox As TextBox = ListView1.InsertItem.FindControl("NameTextBox") NameBox.Text = Page.User.Identity.Name End IfI get a Object not found exception. What is the correct way to find a control inside a InsertItemTemplate and the correct Event to use?

Adding Custom Control to Placeholder


Hi All,

Within a custom control, I am adding a sub-control to a placeholder. Everything runs, but nothing shows up and no postback is triggered on the page.  I've never dynamically added controls before, so I'm probably doing something simple wrong.  Ideas?  The code I'm using is below for reference.


myControl = new CustomControls_rowEventControl();
myControl.Inputs = inList;

PlcTable is the placeholder.  MyControl.Initialize was included because when I assigned inList (which assigns values to the labels) the labels within the control were all null, and would give a runtime error.  The code for the initialize function is:

public void initialize()
        lblMonday = new Label();
        lblTuesday = new Label();
        lblWednesday = new Label();
        lblThursday = new Label();
        lblFriday = new Label();
        lblSaturday = new Label();
        lblSunday = new Label();
        lblName = new Label();
        lblRemarks = new Label();
        linkEdit = new LinkButton();

I am positive that when inList is assigned to the control, the labels are assigned values.  Thanks.

adding usercontrols dynamically to custom control


I have one custom control which inherits from composite control ,i want to  load an usercontrol(.ascx) dynamically with in that custom control and render it to an aspx page

How can  i do that please help me out

Finding control from master page inside tabcontainer in content page


I have a codebehind.vb for a master page from which I'm trying to find a hiddenfield in the content page. I was finding it like this without a hitch...

Dim hfContentSearch As HiddenField = CType(Page.Master.FindControl("main").FindControl("hfSearch"), HiddenField)

Then I decided to add an Ajax TabContainer to the content page. Now I'm having a hard time finding the hiddenfield. I've tried these variations, but still not working.

Dim hfContentSearch As HiddenField = CType(Page.Master.FindControl("main").FindControl("TabContainer1").FindControl("TabPanel1").FindControl("hfSearch"), HiddenField)

Dim hfContentSearch As HiddenField = CType(Page.Master.FindControl("main").FindControl("TabContainer1").FindControl("hfSearch"), HiddenField)

Dim hfContentSearch As HiddenField = CType(Page.Master.FindControl("main").FindControl("TabPanel1").FindControl("hfSearch"), HiddenField)

Can someone please help me with the syntax?

Thank you.


finding control id and setting properties in other pages


hi can anybody help me how to code,

im using a webusercontrol (hide.ascx) it has 2 buttons btn_hide,btn_expand

and in my other forms of all like(products.aspx)customers.aspx,orders.aspx

im using a panel conrol(pnl_products) where in im placing all the input controls.

i want to find the panel control in hide.ascx page and to set that

panel.visble=true/false property in this page.

so that expand and collapse the panel in each page.

Adding Dynamic Rows in ASP.NET GridView Control with TextBoxes and with Delete functionality

In my previous examples, I have demonstrated on how to add dynamic rows in GridView control with TextBoxes and how to save the values into the database. Now, seems that most of the developers are asking if how to add a delete functionality with it. So in this example, I'm going to show on how to delete a certain row in the dynamic GridView with TextBoxes.

Accessing the different controls inside a GridView control

how we can access a particular control which resides inside a GridView control. In this article I will show you how you can access different controls inside a GridView control. We will see how we can access a TextBox control, a DropDownList control and a ListBox control. If you are working with ASP.NET 1.X then you might want to check out my article Accessing Different Controls Inside a DataGrid.

In-Depth look at the GridView Control

In the last article we looked at few of the new controls available in Asp.net 2.0. We also talked about Grid View Control which has replaced the Asp.net 1.1 DataGrid control for good. In this article we will examine more features of the Grid View control. In this article we will see some of the common operations that can be performed using the GridView control. Apart from these operations there are many more functions that can be performed on the control and which we will see in the later articles

ASP.NET repeater control - databind with style

even used the inline editing features, which I at the time thought was the coolest way possible to write ASP.NET code ( I managed to write code to hide all other rows and only show the current one - the row being edited). With a nice looking EditTemplate it looked indeed very slick but it really turned into giant and hard to manage code behind files.

Creating Paging for a Repeater Control

A common question is "How do I implement paging within a Repeater?" Although the beauty of the Repeater control is its flexibility, you're on your own for building most functions. ASP.NET 2.0 has included some new controls that provide paging, as does the DataGrid in ASP.NET 1.1. However, this tip shows you how to roll your own paging for a simple data viewer.

Using TemplateFields in the GridView Control

The GridView is composed of a set of fields that indicate what properties from the DataSource are to be included in the rendered output along with how the data will be displayed. The simplest field type is the BoundField, which displays a data value as text. Other field types display the data using alternate HTML elements. The CheckBoxField, for example, renders as a checkbox whose checked state depends on the value of a specified data field; the ImageField renders an image whose image source is based upon a specified data field. Hyperlinks and buttons whose state depends on an underlying data field value can be rendered using the HyperLinkField and ButtonField field types.

How To Add calendar control inside a GridView

This article show hot to add calendar control inside a GridView with code in c#

Using ATLAS PopUp Control with Calendar inside the GridView Control

In this video tutorial Mohammad demonstrates how you can access the Calendar control which is displayed using the ATLAS PopUp control inside the GridView control.

GridView control to show master-child or master-slave data, written in c#, asp.net

I previously made a master slave datagrid using Visual Studio 2003 .Net (original article) that would allow users to show data to clients using collapse and expand features. These features however did not carry over to gridview for many users. This tutorial will explaing how to create a collapsable/expandable gridview in frameworks 2.0 and higher
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