Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

FindControl with MasterPage, Content, and

Posted on 2012-03-10
2
Medium Priority
?
679 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 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

NEW Veeam Backup for Microsoft Office 365 1.5

With Office 365, it’s your data and your responsibility to protect it. NEW Veeam Backup for Microsoft Office 365 eliminates the risk of losing access to your Office 365 data.

Question has a verified solution.

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

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
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…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …

916 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