ASCX 负载与 ASPX 负载
我真的不能说我完全理解他们如何互动。 特别是当我在 ASCX Load 事件中说 if(Page.IsPostBack) 时,它是什么意思。父ASPX是回发的吗?
提前致谢
I can't really say I fully understand hopw they interact.
Especially when I say if(Page.IsPostBack) in an ASCX Load event, what does it mean. The parent ASPX is postback?
thanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你是对的。 bool 属性 Page.IsPostBack 将告诉您包含 ascx 控件的 aspx 页面是否已提交给自身。 Page 对象指的是 aspx 页面。
You are correct. The bool property Page.IsPostBack will tell you if the aspx page containing the ascx control has been submitted to itself. The Page object refers to the aspx page.
这可能有助于您理解该过程:
在 .aspx 页面上的 Page_Load 上放置一个断点,并在用户控件中的 load 事件上放置另一个断点。运行应用程序并查看事件顺序。
在两个地方创建 Init 事件也可能会有所帮助,这样您就可以逐步浏览它们并查看差异。
如果您当前的代码有点复杂,您可能需要为此目的创建一个单独的示例项目。制作一个“Hello world”.ascx 并将其放在“Welcome”.aspx 上,设置所有断点并单步执行代码。
就我个人而言,我认为这种方法比仅仅阅读它更容易理解和记住。
This might help you understand the process:
Put a breakpoint on Page_Load on the .aspx page, and another breakpoint on the load event in the user control. Run the app and view the sequence of events.
It might also be helpful to create Init events in both places, just so you can step through them and see the differences.
If your current code is a bit complex, you might want to create a separate sample project just for this purpose. Make a "Hello world" .ascx and put it on a "Welcome" .aspx, set all the breakpoints and step through the code.
Personally, I think this approach is easier to understand and remember than just reading about it.