Solved

FindControl() Doesn't work

Posted on 2008-10-06
3
900 Views
Last Modified: 2012-06-27
Hi, I have 3 buttons:

    <asp:Button runat="server" ID="btnSiteDiscount1" onclick="btnSiteDiscount1_Click" />
    <asp:Button runat="server" ID="btnSiteDiscount2" onclick="btnSiteDiscount2_Click" />
    <asp:Button runat="server" ID="btnSiteDiscount3" onclick="btnSiteDiscount3_Click" />

On my PageLoad() i have this code:

        int count = 0;
        foreach (x in y)
        {
            count++;
            Button btn = (Button)this.FindControl("btnSiteDiscount" + count);
            btn.Text = "xxxxxxx";
        }

The problem is that btn == null! why is that and how do I fix it?

Thanks
0
Comment
Question by:giligatech
[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
3 Comments
 

Accepted Solution

by:
giligatech earned 0 total points
ID: 22648615
I forgot to say that I'm working on a page that has Masterpage.
Enetually I figured it and the solution is:

Button btn = (Button)this.Master.FindControl("GeneralContent").FindControl("btnSiteDiscount" + count);

is there another solution?
0
 
LVL 8

Assisted Solution

by:rambovn
rambovn earned 500 total points
ID: 22648644
0
 
LVL 8

Assisted Solution

by:rambovn
rambovn earned 500 total points
ID: 22648659
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

752 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