Solved

FindControl with MasterPage, Content, and

Posted on 2012-03-10
2
672 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 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

The Orion Papers

Are you interested in becoming an AWS Certified Solutions Architect?

Discover a new interactive way of training for the exam.

Question has a verified solution.

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

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
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…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…

623 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