Click here to Skip to main content
15,884,298 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
I am trying to call a method of page1 to page2 using page 1 object in a new win form but the problem is the functionality of the method is which iam calling is working fine in page1 but coming into page 2 its not working.can anyone help me out this...!!
Posted
Comments
F-ES Sitecore 24-Mar-15 5:47am    
Please update your question to include relevant code samples.
Thanks7872 24-Mar-15 5:47am    
Always post smallest possible code snippet of what you have done. Use improve question link at bottom of the question.
BillWoodruff 24-Mar-15 5:56am    
What exactly is a "page object" ?

1 solution

Almost certainly it's the "new win form" part that is giving the problem.

If your Page1 form has a method Called "Foo" which updates the form:
C#
public void Foo(string text)
   {
   myLabel.Text = text;
   }
If you call it from Page1 then it works:
C#
Foo("hello");
But to call it from Page2, you need to access the actual instance of Page1 that is running, and it sounds like you are doing this:
C#
Page1 p1 = new Page1();
p1.Foo("Goodbye");
That won't work, because it is creating a new Page1 and changign that rather than changing the instance you can see. It's like a car: if you put your mobile phone in teh glove box of my car, You don;t expect to find it when you open teh glove box of your car, do you? :laugh:

Have a look at this: Transferring information between two forms, Part 2: Child to Parent[^] = it might make it simpler for you.
 
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