Click here to Skip to main content
15,904,497 members
Please Sign up or sign in to vote.
2.50/5 (2 votes)
See more:
I have a button " TrnsButton" in ViewComplaint.aspx page. Now i wanna access the button from my usercontrol which is caseStageTransition.ascx.cs. so I did the below code in the user control class.Im casting the page to Viewcomplaint then i was able to get the fincontrol intelisence. and now I'm trying to pass the button in findcontrol. the error i'm getting is

C#
Button v = ((ViewComplaint)Page).FindControl("TrnsButton");



1) ErrorAn object reference is required for the nonstatic field, method, or property 'System.Web.UI.Control.Page.get'

2) Error Cannot implicitly convert type 'System.Web.UI.Control' to 'System.Web.UI.WebControls.Button'. An explicit conversion exists (are you missing a cast?)
Posted
Updated 24-Nov-11 6:41am
v2
Comments
rajh7 24-Nov-11 13:26pm    
My ViewComplaint class is a partial class its not static
LanFanNinja 24-Nov-11 14:37pm    
I am not sure why you are getting error 1!
This code should work
Button v = (Button)Page.FindControl("TrnsButton");
So it must have something to do with your casting Page to ViewComplaint.

1 solution

For error 2 you will need to cast to Button
C#
Button v = (Button)((ViewComplaint)Page).FindControl("TrnsButton");
 
Share this answer
 
v5
Comments
Uday P.Singh 24-Nov-11 14:51pm    
yeah the code is running fine! my 5!
LanFanNinja 24-Nov-11 15:05pm    
Thanks

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