ASP.Net:Page

编程入门 行业动态 更新时间:2024-10-28 06:29:35
本文介绍了ASP.Net:Page_Load()被多次调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我对ASP.Net并不了解很多,但是我正在尝试为消息框创建一个新控件.您输入一些信息,然后按一个按钮.

I don't know alot about ASP.Net but I'm trying to make a new control for a message box. You enter some info and press a button.

但是,由于某些奇怪的原因,当按下按钮时,Page_Load()被第二次调用,并且所有成员变量都重置为null!我需要这些变量,并且Page_Load()没有理由再次被调用!当然,调用栈是没有用的.

However, for some bizarre reason when the button is pressed, Page_Load() gets called a second time, and all of the member variables are reset to null! I need those variables, and Page_Load() has not reason to be called a second time! Of course the callstack is useless.

推荐答案

请记住,在ASP.Net中,每次引起任何类型的回发(包括处理按钮单击之类的事件)时,您都在使用一个全新的您必须从头开始重建的页面类.您之前在服务器上构建页面的所有工作都已经完成.这意味着要运行整个页面生命周期,包括页面加载代码,而不仅仅是点击代码.

Remember, in ASP.Net every time you cause a postback of any kind, including handling events like button clicks, you're working with a brand new instance of your page class that must be rebuilt from scratch. Any work you've done previously to build the page on the server is gone. That means running the entire page life cycle, including your page load code, and not just the click code.

总是有两个,不多也不少.请求和响应.

Always two there are, no more, no less. A request and a response.

更多推荐

ASP.Net:Page

本文发布于:2023-11-10 15:36:39,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1575764.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:ASP   Net   Page

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!