Solved

FindControl with MasterPage, Content, and

Posted on 2012-03-10
2
668 Views
Last Modified: 2012-03-10
I have a MasterPage, Content, and aspx page within the Content.
I need to find a control using the string ID of the control to be found.


<%@ Page Language="C#" MasterPageFile="~/MasterPage.master"
AutoEventWireup="true" CodeFile="UploadImage.aspx.cs"
Inherits="UploadImage"  Title="Upload Images" Debug ="true" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
    <title>HoldemMyWay Helper</title>
   
     <style type="text/css">
        .style2
        {
            margin-right: 0px;
        }
        </style>
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder" Runat="Server">

<b>HoldemMyWay Helper </b>&nbsp;

<asp:ImageButton ID="cmdc1Clip" runat="server" Height="32px"
        ImageUrl="~/CardImages/c1Clip.gif" Width="25px" OnClick="cmdc1Clip_Click"/>    <br />
    <br />

====
The following syntax compiles but returns a null value for the control.
and the following error:
Object reference not set to an instance of an object.

 ImageButton MyControl = (ImageButton)this.Master.FindControl("Content2").FindControl("ContentPlaceHolder").FindControl("cmdc1Clip");  

What do you suggest?

Thank you,
0
Comment
Question by:Dovberman
2 Comments
 
LVL 7

Accepted Solution

by:
markmiddlemist earned 500 total points
ID: 37704864
Try using the FindControlRecursive method shown here - http://www.dreamincode.net/code/snippet1663.htm - to search for cmdc1Clip

so it would become FindControlRecursive(this.Master, "cmdc1Clip")
0
 

Author Comment

by:Dovberman
ID: 37704896
I made the following change for an ImageButton:

 ImageButton MyControl = (ImageButton) FindControlRecursive(this.Master, "cmdc1Clip");

Thanks,
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

803 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question