如何从特定班级获得特定控制权 [英] How to reach specific control from specific Class

查看:68
本文介绍了如何从特定班级获得特定控制权的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我在名为Globle的Web应用程序项目中上课,
并假设我有一个名为Homepage的页面.

我想知道如何从Globle Class达到首页中的特定控件,如下所示:

Hi,

I make class in my web application project called Globle,
and suppose i have page called Homepage.

I want to know how to reach specific control in Homepage from Globle Class as like this:

public class Globle
    {
        public static bool myMethod(Page Homepage)
        {
            Homepage.Controls.TextBox.Text = "any thing";

            return true;
        }
    }



谢谢.



thanks.

推荐答案

是的,可以.

试试,

Yeah you can.

Try,

(HomePage.FindControl("YOU_CONTROL_ID") as TextBox).Text = "Any thing";



您可能会在运行时获取NullException,因为



You might get NullException on runtime as because

HomePage.FindControl("YOU_CONTROL_ID")




or

HomePage.FindControl("YOU_CONTROL_ID") as TextBox


可以为null.添加适当的null异常处理就可以了.

我不确定它是什么类型的ASP.NET项目.您可以将Page中的控件的访问修饰符更改为public,然后像在问题中所说的那样访问它是否是Web应用程序.


can be null. Add appropriate null exception handling get going with it.

I am not sure what type of ASP.NET project is it. You can change the access modifier of the control in Page to public and access like you said in your question if it is Web Application.


这篇关于如何从特定班级获得特定控制权的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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