FindControl找不到FormView中嵌入的按钮 [英] FindControl does not find a button embedded within a FormView

查看:61
本文介绍了FindControl找不到FormView中嵌入的按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试对该功能进行编码,以切换System.Web.UI.Controls.Enabled属性.

我实际上可以从未嵌入的网页上读取TextBox,但是,我无法到达" FormView(ID = Envelope)中嵌入的Button.

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)

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");
        }
    }



我正在使用VS 2008/Win XP SP 3/.NET 3.5 SP1.完整的源代码此处.

我正在关注此MSDN文章.

:confused:

版本信息



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>

推荐答案

FindControl不会在模板中找到控件,因为如果您有一个模板,且该模板具有多行,那么它怎么做知道找到哪一个吗?您需要遵循以前给出的建议,而不是这样做.无论如何,FindControl都是丑陋的,我尝试避免这种情况.
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.


这篇关于FindControl找不到FormView中嵌入的按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆