参考的.aspx从物业的.ascx [英] Reference .aspx property from .ascx

查看:96
本文介绍了参考的.aspx从物业的.ascx的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

结果
我还想从我的.ascx引用我的.aspx的属性。


Id like to reference a property in my .aspx from my .ascx.

比方说我的网页类是:

public partial class MyAdminPage : System.Web.UI.Page

我期待我可以从我的.ascx做的:

I was expecting I could do from my .ascx:

MyAdminPage myPageInstance =(MyAdminPage)this.Page;

MyAdminPage myPageInstance = (MyAdminPage)this.Page;

MyAdminPage myPageInstance = this.Page为MyAdminPage;

MyAdminPage myPageInstance = this.Page as MyAdminPage;

这点我不能。

我怎么能引用我的网页类从的.ascx?

How could I reference my page class from the .ascx?

更新1

谢谢你的答复。

我忘了提,在.aspx有一个母版页,而内的ContentPlaceHolder是我拥有的.ascx控制。

I forgot to mention that the .aspx has a master page, and within the contentPlaceholder is where I have the .ascx control.

所以从我的.ascx如果我这样做:结果
this.Parent - >我得到一个参考的ContentPlaceHolder结果
this.Parent.Parent - >我得到一个参考的HtmlForm结果
this.Parent.Parent - >参照母版。

So from my .ascx if I do:
this.Parent --> I get a reference to "ContentPlaceHolder"
this.Parent.Parent --> I get a reference to "HtmlForm"
this.Parent.Parent --> reference to a 'MasterPage'.

我不会重用的.ascx其他任何.aspx页只是一个。

I will not reuse the .ascx in any other .aspx pages just the one.

推荐答案

sJohnny的评论则恰如其分,你不应该试图从孩子(控制)修改父(页)属性。处理这种情况的一个好方法是为孩子时,它需要家长采取行动,引发事件。这样,家长可以直接订阅事件并调用它需要在那个时候任何属性。这样,你的用户控件绝不依赖于这个特定页面的实现。

sJohnny's comment is spot on, you should not be trying to modify parent (page) properties from the child (control). One good way to handle this situation is for the child to raise an event when it needs the parent to act. That way the parent can simply subscribe to the event and call whatever properties it needs at that time. This way your user control is in no way tied to the implementation of this particular page.

这篇关于参考的.aspx从物业的.ascx的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆