ASP.Net:Page_Load()被多次调用 [英] ASP.Net: Page_Load() being called multiple times

查看:67
本文介绍了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_Load()被多次调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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