Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

FindControl with MasterPage, Content, and

Posted on 2012-03-10
2
Medium Priority
?
674 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 7

Accepted Solution

by:
markmiddlemist earned 2000 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

Quick Cloud Training

Looking for some quick training on the cloud in 2 hours or less? Check out these how-to guides in AWS, Linux, OpenStack, Azure, and more!

Question has a verified solution.

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

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
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…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…

670 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