Solved

FindControl with MasterPage, Content, and

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
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 demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

758 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now