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

x
?
Solved

FindControl() Doesn't work

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

Assisted Solution

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

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses

783 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