开发者

Get parent page values from the usercontrol

How to g开发者_如何学Goet 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.


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.


The Page property? http://msdn.microsoft.com/en-us/library/system.web.ui.control.page.aspx

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜