Click here to Skip to main content
15,891,409 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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
C#
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'

Question number 2)
When i put the code inside a function the key word "Page" turns from blue to black why is that?
Posted
Updated 24-Nov-11 7:57am
v2
Comments
Sergey Alexandrovich Kryukov 24-Nov-11 14:33pm    
Tell us the types Page, Button and ViewComplaint, fully qualified. Do you have instance also called "Page"?
--SA

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:

C#
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:
C#
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)
        {


        }

    }
}


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 :)
 
Share this answer
 
v7
Comments
Sergey Alexandrovich Kryukov 24-Nov-11 14:32pm    
No, no. Why casting first to ViewComplaint and then to Button? I also doubt that a cast to a type named "Page" to "Button" is valid, too.
--SA
Uday P.Singh 24-Nov-11 14:36pm    
yeah you are right thanks let me update..
rajh7 24-Nov-11 14:35pm    
To make an instance of the Page I tried the following
1) Page mypage = this.Page the it says key word this not awaylable in this context.

2) Page p = new Page();
now it says a initializer canot reference something like that

How can I make an instance please

thank you for your previous answers thos are valuable ..appreciate it
Remove the static keyword from your method...
 
Share this answer
 
Comments
rajh7 24-Nov-11 14:09pm    
I dont have any static key word in my method.

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