How to get the parent page values from the usercontrol. I have a usercontrol in a page. On click of the usercontrols button i wanna get some values from the page after executing a method. i need those values in my usercontrol. What is the best way to get the results of the page in the usercontrol.
The Page property? http://msdn.microsoft.com/en-us/library/system.web.ui.control.page.aspx
Raw way: First access Page property:
http://msdn.microsoft.com/en-us/library/system.web.ui.control.page.aspx
Next You can cast Page property to Your page type (whatever it is) or You can use Page.FindControl method to find Page values from other controls.
http://msdn.microsoft.com/en-us/library/31hxzsdw.aspx
In nice way, user control should expose event fired when this button has been clicked and page should subscribe to this event and return data to control.
Is this what You are looking for?
You can use the Page
property to get a reference to the page object. However, the reference is not of the type of your specific page class, so you can't use it to access the specific members in the class without casting it first:
MySpecificPageClass page = (MySpecificPageClass)Page;
Now you can use the reference to access any public members of the class. Controls in the page are often declared as protected, so you might have to change their access level to public in order to access them from the outside.