Click here to Skip to main content
15,891,842 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm trying to code this function that toggles the System.Web.UI.Controls.Enabled property.

I could actually read a TextBox off a Webpage, that is NOT embedded, however, I couldn't "reach" the Button embedded within the FormView (ID=Envelope)

C#
protected void btnEdit_Click(object sender, EventArgs e)
    {
        toggleButton_Enabled("btnSave", true);
    }
    private void toggleButton_Enabled(String _ButtonID, Boolean _enable)
    {
        /*
         * This function sets a System.Web.UI.WebControls.Button.Enabled property to 'true' if it is 'false', and,
         * conversely, sets System.Web.UI.WebControls.Button.Enabled property to 'false' if it is 'false'.
         *
        * @param TextBoxID must be a System.Web.UI.WebControls.Button
        * @param _enable - forces the control to be enabled
        */
        Button mpButton = new Button();
        mpButton = (Button)this.FindControl(_ButtonID);
        mpButton = (Button)FindControl(_ButtonID);
        if (mpButton != null && mpButton.Enabled)
        {
            mpButton.Enabled = false;
        }
        else if (mpButton != null && !(mpButton.Enabled))
        {
            mpButton.Enabled = true;
        }
        else if (mpButton != null && _enable)
        {
            mpButton.Enabled = false;
        }
        else if (mpButton == null)
        {
            throw new Exception(mpButton.ToString() + "is null");
        }
    }


I'm using VS 2008 / Win XP SP 3 / .NET 3.5 SP 1. Complete source code here. Screenshots here.

I'm following this MSDN article.

:confused:

Version information
Microsoft Visual Studio 2008
Version 9.0.21022.8 RTM
Microsoft .NET Framework
Version 3.5 SP1

Installed Edition: Professional

Microsoft Visual Basic 2008   91605-270-9885354-60939
Microsoft Visual Basic 2008

Microsoft Visual C# 2008   91605-270-9885354-60939
Microsoft Visual C# 2008

Microsoft Visual C++ 2008   91605-270-9885354-60939
Microsoft Visual C++ 2008

Microsoft Visual Studio 2008 Tools for Office   91605-270-9885354-60939
Microsoft Visual Studio 2008 Tools for Office

Microsoft Visual Web Developer 2008   91605-270-9885354-60939
Microsoft Visual Web Developer 2008

Crystal Reports    AAJ60-G0MSA4K-68000CF
Crystal Reports Basic for Visual Studio 2008


Hotfix for Microsoft Visual Studio 2008 Professional Edition - ENU (KB944899)   KB944899
This hotfix is for Microsoft Visual Studio 2008 Professional Edition - ENU.
If you later install a more recent service pack, this hotfix will be uninstalled automatically.
For more information, visit http://support.microsoft.com/kb/944899.

Hotfix for Microsoft Visual Studio 2008 Professional Edition - ENU (KB945282)   KB945282
This hotfix is for Microsoft Visual Studio 2008 Professional Edition - ENU.
If you later install a more recent service pack, this hotfix will be uninstalled automatically.
For more information, visit http://support.microsoft.com/kb/945282.

Hotfix for Microsoft Visual Studio 2008 Professional Edition - ENU (KB946040)   KB946040
This hotfix is for Microsoft Visual Studio 2008 Professional Edition - ENU.
If you later install a more recent service pack, this hotfix will be uninstalled automatically.
For more information, visit http://support.microsoft.com/kb/946040.

Hotfix for Microsoft Visual Studio 2008 Professional Edition - ENU (KB946308)   KB946308
This hotfix is for Microsoft Visual Studio 2008 Professional Edition - ENU.
If you later install a more recent service pack, this hotfix will be uninstalled automatically.
For more information, visit http://support.microsoft.com/kb/946308.

Hotfix for Microsoft Visual Studio 2008 Professional Edition - ENU (KB946344)   KB946344
This hotfix is for Microsoft Visual Studio 2008 Professional Edition - ENU.
If you later install a more recent service pack, this hotfix will be uninstalled automatically.
For more information, visit http://support.microsoft.com/kb/946344.

Hotfix for Microsoft Visual Studio 2008 Professional Edition - ENU (KB946581)   KB946581
This hotfix is for Microsoft Visual Studio 2008 Professional Edition - ENU.
If you later install a more recent service pack, this hotfix will be uninstalled automatically.
For more information, visit http://support.microsoft.com/kb/946581.

Hotfix for Microsoft Visual Studio 2008 Professional Edition - ENU (KB947171)   KB947171
This hotfix is for Microsoft Visual Studio 2008 Professional Edition - ENU.
If you later install a more recent service pack, this hotfix will be uninstalled automatically.
For more information, visit http://support.microsoft.com/kb/947171.

Hotfix for Microsoft Visual Studio 2008 Professional Edition - ENU (KB947173)   KB947173
This hotfix is for Microsoft Visual Studio 2008 Professional Edition - ENU.
If you later install a more recent service pack, this hotfix will be uninstalled automatically.
For more information, visit http://support.microsoft.com/kb/947173.

Hotfix for Microsoft Visual Studio 2008 Professional Edition - ENU (KB947180)   KB947180
This hotfix is for Microsoft Visual Studio 2008 Professional Edition - ENU.
If you later install a more recent service pack, this hotfix will be uninstalled automatically.
For more information, visit http://support.microsoft.com/kb/947180.

Hotfix for Microsoft Visual Studio 2008 Professional Edition - ENU (KB947540)   KB947540
This hotfix is for Microsoft Visual Studio 2008 Professional Edition - ENU.
If you later install a more recent service pack, this hotfix will be uninstalled automatically.
For more information, visit http://support.microsoft.com/kb/947540.

Hotfix for Microsoft Visual Studio 2008 Professional Edition - ENU (KB947789)   KB947789
This hotfix is for Microsoft Visual Studio 2008 Professional Edition - ENU.
If you later install a more recent service pack, this hotfix will be uninstalled automatically.
For more information, visit http://support.microsoft.com/kb/947789.

Hotfix for Microsoft Visual Studio 2008 Professional Edition - ENU (KB948127)   KB948127
This hotfix is for Microsoft Visual Studio 2008 Professional Edition - ENU.
If you later install a more recent service pack, this hotfix will be uninstalled automatically.
For more information, visit http://support.microsoft.com/kb/948127.

Hotfix for Microsoft Visual Studio 2008 Professional Edition - ENU (KB953256)   KB953256
This hotfix is for Microsoft Visual Studio 2008 Professional Edition - ENU.
If you later install a more recent service pack, this hotfix will be uninstalled automatically.
For more information, visit http://support.microsoft.com/kb/953256.

Hotfix for Microsoft Visual Studio 2008 Professional Edition - ENU (KB971091)   KB971091
This hotfix is for Microsoft Visual Studio 2008 Professional Edition - ENU.
If you later install a more recent service pack, this hotfix will be uninstalled automatically.
For more information, visit http://support.microsoft.com/kb/971091.

Hotfix for Microsoft Visual Studio 2008 Professional Edition - ENU (KB973674)   KB973674
This hotfix is for Microsoft Visual Studio 2008 Professional Edition - ENU.
If you later install a more recent service pack, this hotfix will be uninstalled automatically.
For more information, visit http://support.microsoft.com/kb/973674.

PowerCommands for Visual Studio 2008   1.0
A set of power commands for Visual Studio 2008

Update for Microsoft Visual Studio 2008 Professional Edition - ENU (KB972221)   KB972221
This update is for Microsoft Visual Studio 2008 Professional Edition - ENU.
If you later install a more recent service pack, this update will be uninstalled automatically.
For more information, visit http://support.microsoft.com/kb/972221.
<pre>
Posted
Updated 31-Aug-10 11:26am
v3

1 solution

FindControl isn't going to find a control inside a template, because if you have a template, with more than one row, how does it know which one to find ? You need to follow the advice you were given before, instead of doing it this way. FindControl is, in any case, an ugly hack, I try to avoid it.
 
Share this answer
 
Comments
jon-80 31-Aug-10 17:28pm    
Thanks for that, any idea what might work?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900