错误:需要对象引用 [英] Error : An object reference is required

查看:75
本文介绍了错误:需要对象引用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

谢谢您的回答.
用户控件类为CasestageTransitioncotrol.ascx.cs是局部类.我的页面是VewComplaint.aspx,后面的代码是VewComplaint.aspx.cs

Thank you for the answer.
User control class is CasestageTransitioncotrol.ascx.cs is a partial class. My page is VewComplaint.aspx and the code behind is VewComplaint.aspx.cs

Button b = (Button)((ViewComplaint)Page).FindControl("transitionStageBtn");


当我编译上面的代码时,它只会抱怨类似
的页面


when i compile the above code its only complaining about the page like

Error	3	An object reference is required for the nonstatic field, method, or property 'System.Web.UI.Control.Page.get'


问题编号2)
当我将代码放入函数中时,关键字页面"从蓝色变为黑色,这是为什么?


Question number 2)
When i put the code inside a function the key word "Page" turns from blue to black why is that?

推荐答案

您可能正在尝试访问non-static财产.但是顺便说一句,我的代码运行良好.您在VewComplaint.aspx.cs中的哪个位置编写了此代码,并确保您在同一行中遇到异常,那么我们可以为您提供更好的服务.

您是否写过这样的内容:

You may be trying to access the non-static property. But BTW your code is running good at my end. Where do you have written this code in your VewComplaint.aspx.cs and make sure you are getting the exception in the same line, then we can serve you better.

Have you written something like this:

namespace WebApplication1
{
    public partial class ViewComplaint : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

            Button b = (Button)((ViewComplaint)Page).FindControl("transitionStageBtnm");
        }

    }
}



上面的代码在我的末端运行良好.确保您不要写下了这样的内容:



the above code is running fine at my end. Make sure you don''t have written something like this:

namespace WebApplication1
{
    public partial class ViewComplaint : System.Web.UI.Page
    {
        Button b = (Button)((ViewComplaint)Page).FindControl("transitionStageBtnm");
        protected void Page_Load(object sender, EventArgs e)
        {


        }

    }
}



这将给出错误:Error 1 An object reference is required for the non-static field, method, or property ''System.Web.UI.Control.Page.get''
希望对您有所帮助:)



this will give the error:Error 1 An object reference is required for the non-static field, method, or property ''System.Web.UI.Control.Page.get''
hope it helps :)


从您的方法中删除static 关键字...
Remove the static keyword from your method...


这篇关于错误:需要对象引用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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