Click here to Skip to main content
15,897,891 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm trying to access a method on my mainpage from another page. The mainpage method is "public". when I call it, I get an error "object reference not set to an instance of an object." It works fine from mainpage!! :confused:
Posted

Are you navigating from one page to another? If that is the case, then you can't directly do. You have to create the instance of the MainPage and then you can call the public method:

MainPage mainPage = new MainPage();<br />
mainPage.DoCall();<br />


If your mainpage is still loaded in memory as the base page & on top of it if you are loading any UserControl then you can easily access it from the instance.

If this solves your problem, please "Mark As Answer", and if you are using some other mechanism to load one page from another, please elaborate the same. It will be easier for us to help you out.

Thank you for posting in CodeProject.
 
Share this answer
 
You need to post some code here - some object in your main page might be null and if someone here looks at the code, they might be able to give you a solution.
 
Share this answer
 
How are you accessing the main instance of MainPage? I suspect it is set to null.
 
Share this answer
 

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