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

x
?
Solved

FindControl() Doesn't work

Posted on 2008-10-06
3
Medium Priority
?
906 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 2000 total points
ID: 22648644
0
 
LVL 8

Assisted Solution

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

Featured Post

URL rewriting in AWS CloudFront

A quick how-to guide to implement with a Lambda function!

Question has a verified solution.

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

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 …
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…

722 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