Solved

FindControl() Doesn't work

Posted on 2008-10-06
3
896 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
  • 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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

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…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…

773 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