繁体   English   中英

ASP.NET中的C#Winforms控制循环方法

[英]c# winforms control loop method in asp.net

我在winforms c#中获得了这种方法,它可以完美工作。 但是我无法弄清楚如何使asp.net网页的此方法完全相同。 任何一点帮助将不胜感激。

public static void rat(Form x)
    {
        Form myForm = x;
        foreach (Control c in myForm.Controls)
        {
            if (c.Name != "ctn" && !(c is Label))
            {
                c.Enabled = !(c.Enabled);
            }
        }
    }

只需更改以下两行。 由于它是ASP.NET应用程序,因此您期望使用Page实例而不是Form实例。 因为每个ASP.NET Web窗体所继承Page在基类中同样Winform各种形式从继承Form基类。

public static void rat(Page x)
    {
        Page myPage = x;

考虑到您的Webform名称为webform1 ,您可以执行此操作

public static void rat(Page x)
    {
        webform1 myForm = (webform1)x;
        foreach (Control c in myForm.Controls)
        {
            if (c.Name != "ctn" && !(c is Label))
            {
                ((Label)c).Enabled = !((Label)c).Enabled);
            }
        }
    }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM