.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

How to find a control from a contentpage when looking from the masterpage?

Posted By:      Posted Date: October 07, 2010    Points: 0   Category :ASP.Net

I have a FreeTextBox control on a page that has a masterpage. This FreeTextBox control is in the maincontent.
I also have a button on the masterpage. If this button is clicked I want to know if I'm in the page with the FreeTextBox.
How can I do this. I have tried:
findTxtBox = this.Master.FindControl("MainContent").FindControl("base").FindControl("FreeTextBox1") as FreeTextBoxControls.FreeTextBox;
To see if findTxtBox is not null. But

View Complete Post

More Related Resource Links

Unable to find Control ID of Dropdownlist Control of a UserControl from a ContentPage


I am implementing Master Pages in my existing project.

I am getting following Error:

" Unable to find control id '_ctl0:ContentPlaceH?older1:drop1:drop1' referenced by the 'ControlToValidate' property of 'valCust1'. "

I have a ContentPage which is refering to a UserContol. This UserControl has a DropDownList Control which i need to validate.

I am using a CustomValidator to validate the Dropdownlist and this CustomValidator is placed in the ContentPage.

The ControlToValidate Property of the CustomControl is assigned programatically as
(in ASPX.cs)

Control CTRL1;

ContentPlaceHolder cntplcHolder = (ContentPlaceHolder)?this.Master.FindCont?rol("ContentPlaceHol?der1");

 CTRL1 = cntplcHolder.FindCon?trol("drop1").FindCo?ntrol("drop1");

 valCust1.ControlToValidate = CTRL1.UniqueID;

My .ASPX page contains

<%@ Register TagPrefix="it" TagName="PickCntl1" Src="~/UserControls/?PickCntl1.ascx" %>

<it:PickCntl1 id="drop1" Runat="Server" Required="true" DisplayDefault="true?"></it:PickCnt?l1>


find a Control inside a GridView using jQuery


I have databound GridView in my page and I have a hidden DIV in all rows. Each row contains a Button that I want it to make the DIV visible for me! how can I use that with jQuery?!

here is the code page: 

<asp:GridView ID="GridView2" runat="server" AutoGenerateColumns="False" 
                                EnableModelValidation="True" GridLines="None" ShowHeader="False" Width="100%">

Cant find vsi file for CSS Friendly Control Adapters


Hi guys

This is driving me crazy... I cant find the .vsi file for installing the CSS Friendly Control Adapters Project. Does anyone know where I can get this?

The following link: http://www.asp.net/cssadapters/ only leads to the CodePlex wiki where I can download the dll and a partial solution. Essentially, I'm looking for the source code to implement the Menu adapter.

Any help is much appreciated!

Find a header control


Via RowDataBound, how to find a control in the header row?

This is what I have but not working!!!

If e.Row.RowType = DataControlRowType.Header Then
  Dim cbHeader As CheckBox = CType(GV_update.HeaderRow.FindControl("HeaderLevelCheckBox"), CheckBox)
End If


Can't Find DropDownList In Control Parameter

I have a page with 2 Content Controls. Content1 has a SqlDataSource with a Control Parameter
that uses a Dropdown list. The dropdownlist is in Content2. I used viewsource to get
the dropdownlist control name which was
ctl00_ContentPlaceHolder6_ddlPersonFilter. I also got an error if I used ddlPersonFilter.
Thanks for any assistance.

Could not find control 'ctl00_ContentPlaceHolder6_ddlPersonFilter' in ControlParameter ''.

<%@ Page Title="Deal ToDos" Language="VB" MasterPageFile="~/Protected/secureds_deal.master" 
                            EnableTheming="true" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>
<%@ MasterType 

Problem in Custom Control Unable to find Control To Validate Property


I make a custome control by taking a TextBox and A Regular Expression Validator.When i Use this on a .aspx page it works fine.But when i use this on .ascx page and dynamically load user control on a place holder in .aspx page it through an Error

Unable to find control id '_ctl0:txtEmail' referenced by the 'ControlToValidate' property of '_ctl0:txtEmailRequired'


My Custome control Code is this"--

public class EmailValidator:System.Web.UI.Control, INamingContainer{

private System.Web.UI.WebControls.TextBox textBox;

private System.Web.UI.WebControls.RegularExpressionValidator regularExpressionValidator;

public EmailValidator(){

textBox = new TextBox();

regularExpressionValidator = new RegularExpressionValidator();

IsErrorTextBelow = true;

IsRequired = false;

how to find control from header template of a datalist?

 Hi,I have a textbox in header template of a datalist. From code behind i've to access these textbox from page_load event.I tried with the following code. DataList.Controls[0].FindControl("myControl") But it have error. how to solve it? 

Find Control in ListView ItemTemplate

I want to pass the checked checkboxes value of my listview control to a second page so I can display the listview in this second page  with only those selected recordsthis is what I am have so far , but dont really know how to get it to work the desire way.. Code is working but I am afraid that chekcbox and listview values for my loop are not correctMuch help is appreciated!! page1 codeProtected Sub ListView1_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.ListViewItemEventArgs) Handles ListView1.ItemDataBound        Dim recordsId As New List(Of String)        Dim chb As CheckBox = DirectCast(ListView1.FindControl("CheckBoxPrintProvider"), CheckBox)        For Each lvi As ListViewItem In ListView1.Items            ' Dim chb2 As CheckBox = DirectCast(lvi.FindControl("CheckBoxPrintProvider2"), CheckBox)            ' Check if the checkboxes are checked             ' If (chb.Checked Or chb2.Checked) Then            '  If chb.Checked Then        &nbs

find the label control of gridview in save button event in C#

hi, every one..i want save the gridview in buttonsave event..here i wrote the code like thisfor (int i=0;i<gridview1.row.count;i++){label lbl=(label)gridview1.rows[i].findcontrol("lbl");Textbox txtname=(Textbox)gridview1.rows[i].findcontrol("txtname");}here i got the textbox value but am not getting label value how to get that label value..thanks in advance

Find a form control that is created after postback

HiI have a drop down list (created during form design) with auto postback enabled. And I use AJAX to prevent 'visible postback'. When a user choose an item from the drop down list, the system will then perform a postback and created a set of form control's such as label, drop down list and text box for entry.Then, I will have a button (created during form design), and when I click on the button, i want to find for the form control that are created after the post back, but I cant find them!I wonder if those form controls are render to the web form?? But I have no problem finding the drop down list that is created during design time.Anyway I can find those form controls?Thank You.

WPF : Find a control in GridView

I have googled a lot to find the answer to my question but no suitable answer could be found. I am using a gridview of wpf tool kit. which has multiple columns  column structure is like,   <my:DataGridTemplateColumn MaxWidth="15" MinWidth="15" Width="15"> <my:DataGridTemplateColumn.CellTemplate> <DataTemplate> <Button Click="btnContractCollespe_Click" FontSize="9" Height="20" Name="btnContCollespe">+</Button> </DataTemplate> </my:DataGridTemplateColumn.CellTemplate> <my:DataGridTemplateColumn.CellEditingTemplate> <DataTemplate /></my:DataGridTemplateColumn.CellEditingTemplate> </my:DataGridTemplateColumn> <my:DataGridTemplateColumn> when grid renders it displays button "btnContCollespe" in each row. I want some how I could change contents of every button in all rows. Basically this button will expand and collapse gridview 3 fixed columns. so upon expand operation, buttons in all rows should have content "-" and after user performs collapse operation, all button content should change to +. I found no suitable way to find control inside grid. Can anybody help. In asp.net we used to do it by gridview.findcontrol("...") but no such method is available in WPF gridview. please provi

access control from masterpage

How do I get access to the below linkButton control from my Master page or a page using that Master, this is in my Master page:<Project:RoleControl ID="RoleControl1" runat="server"> <AdminTemplate> <li id="liadmin" runat="server"><asp:LinkButton id="lnkAdmin" PostBackUrl="~/admin/admin.aspx" runat="server" CausesValidation="false">Admin</asp:LinkButton></li> </AdminTemplate> </ Project:RoleControl> Basically it's a custom control I built which will allow me to show certain things only to admin users, we are not using asp.net membership so I came up with a control that works. But when I try to access it within the Master page itself it keeps saying the control has 0 count in it, I'm doing this check in the Page_Load event:if (RoleControl1.Controls.Count > 0) { string roleControlId = RoleControl1.Controls[0].ID; ((HtmlGenericControl)RoleControl1.FindControl(roleControlId)).Attributes["class"] = "navselected"; } But the RoleControl1.Controls.Count check is always 0. I know the control is rendering as I can see it when the page loads, the link comes up. I thought maybe I'm checking it in the incorrect event, rather than Page_Load should I be checking for it in another event, could it be that at that point

find control inside datalist


I want to find control inside datalist, i am using this:


//here got error: Index was out of range. Must be non-negative and less than the size of the collection.

here is my aspx code:

<asp:DataList ID="DataList1" runat="server" DataKeyField="nsid">
     <asp:Label ID="Label1" Text='<%# Eval("ncompany") %>' Runat="Server" CssClass="subject&quo

find control in datalist by javascript(Not by Code Behind CS Page or ItemDatabound)


Hello all,

I am facing a problem with javascript.Following is the scenario:

I am working on survey application......

I have taken a datalist in which the question in survey are bound in a label control

now user can change color of the question using color picker

color picker have a popup which is closed when user selects a color and

the color of question will be updated as popup closes

So i have to find label control(in which i bound questions)

in datalist by javascript only (not by Cs page or by itemdatabound event because of color picker popup i can not use cs page)

and update the color of label selected by color picker

I googled and found following code but it show null value

var lbl = document.getElementById('<%= Page.Master.FindControl("ContentPlaceHolder1").FindControl("dList").FindControl("lblQuestion") %>');

when I saw the page source following id is generated for label

and so on


Unable to find Control in List



I'm trying to define the parameters of my data source using a stored procedure. My Stored Procedure Syntax is perfect and i'm happy with that, i've just got trouble with connecting my parameters to my controls. I have 19 Parameters, of which i've managed to connect 17 to controls within my ASP.Net form (some to text boxes, some to ddls etc...)

However, i'm trying to connect a particular parameter to a control, but when i drop down my list of controls it's not visible? The control is within a hidden panel so i've un-hidden it and it's still not there. I've even commented out the panel and tried that but i can't find this control! I just cant seem to get this control to appear in the list.

Has any one seen anything like this before at all?

If you need any more information please let me know. (for clarirty i've attached screen grab)

Control Not in list


ConfirmButtonExtender and ModalPopupExtender Server Control with Master Page Failed to find element


I am in the process of building a server control that contains a ConfirmButtonExtender. This is my code:

The Master Page:

<%@ Master Language="VB" CodeFile="MasterPage.master.vb" Inherits="CBC_MasterPage" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <asp:ContentPlaceHolder id="head" runat="server">
    <form id="form1" runat="server">
        <asp:ContentPlaceHolder id="ContentPlaceHolder1" runat="server">

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