在Web应用程序的页面生命周期中,按钮单击事件发生在哪个阶段? [英] What stage does a button click event occur in the page life cycle of a web app?

查看:153
本文介绍了在Web应用程序的页面生命周期中,按钮单击事件发生在哪个阶段?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨...

应用类型:Web应用
SDE:Visual Studio 2008专业版
代码:asp.net和c#
使用IE 8

我在编写的基于Web的应用程序中遇到一个问题,如果我理解当有人单击与事件的单击处理程序相关的提交按钮时展开的确切步骤,则可能可以更好地解决该问题.我可以在页面生命周期"本身上找到许多细节,但是什么时候发生与提交按钮的单击处理程序相关的事件的实际代码何时发生?抱歉,如果下一个问题听起来很愚蠢,但是该事件是否在与页面循环相同的线程中触发或单独触发?
除此之外,我应该清楚地描述我的实际问题,因为它甚至可能与此无关.我正在做的是基于Page_Load中的XML文件的内容创建动态控件(在非回发期间).在创建每个动态控件时,我将它们添加到主面板(附加到主页)中,并将每个控件添加到ArrayList Session-Variable(请参见下面的代码).然后,我在一种方法中使用此Session-Variable,然后在Page_Load事件期间(回发期间)将动态控件读取到主面板中. 然后,在附加到提交"按钮的OnClick事件中,我检查控件的状态(请注意,控件主要由复选框列表"和单选按钮列表"组成),并根据结果使用标签显示消息.在大约90%的情况下,此方法效果很好,但是办公室中的3台特定计算机在调用OnClick事件处理程序内的FindControl时收到错误消息,如果我通过遍历页面上的所有控件(包括子控件)进行测试,似乎没有动态控件存在于事件处理程序中的那个阶段.该问题特定于这3台特定的计算机,并且将始终失败(不是间歇性的)并且不清除IE缓存,重新启动计算机将使其正常运行.我们运行一个标准操作环境,因此每个人都具有与运行IE 8的XP(Service Pack 3)相同的内部版本.
使事情变得更加奇怪的是(这确实让我很茫然)如果我复制aspx和cs文件并更改其名称,然后使用相同的问题机器来运行该副本,那么它可以正常工作吗? ?但是,我不乐意将其留在那,因为我认为该错误将再次出现,因为我认为从事件的角度来看这可能是一个时间问题.此外,我们还尝试在托管Web应用程序的服务器上重新启动IIS服务.
我没有添加太多代码,因为我不想太长篇幅,并且认为任何代码片段都只会重申我在上面描述的内容.如果有人认为我的C#代码可以帮助让我知道,我将再发送一些有关我如何进行此操作的摘要.

我向会话var添加控件的代码段

Hi...

App Type: Web Application
SDE: Visual Studio 2008 Pro Edition
Code: asp.net and c#
Using IE 8

I am having an issue in a web based application that I have written that I might be able to better resolve if I understand the exact steps that unfold when someone clicks a submit button that has an event tied to it''s click handler. I can find heaps of details on the Page Life cycle itself and what stage does what however when does the actual code for the event tied to the submit button''s click handler happen? Sorry if the next question sounds stupid however does the event fire in the same thread as the page cycle or seperately?
That aside I should clearly describe my actual issue as it might not even be related to this. What I am doing is creating dynamic controls based off the contents of an XML file at Page_Load (during non postback). As I create each dynamic control I add them to a main Panel (which is attached to the main page) and I add each control to an ArrayList Session-Variable (see code below). I then use this Session-Variable in a method that then readds the dynamic controls to the Main Panel during the Page_Load event (during postback).
In the OnClick event attached to the Submit button I then check the state of the controls (please note the controls mainly consist of CheckBox Lists and Radio Button Lists) and display a message using a label depending on the results. This works great in around 90% of cases however 3 specific computers around the office receive an error during a call to FindControl inside the OnClick event handler and if I test by reiterating through all controls (including children) on the page it seems none of the dynamic controls exist at that stage inside the event handler. The problem is specific to those 3 particular machines and will always fail (not intermittent) and no clearing of IE cache, restarting the machine will make it work. We run a Standard Operating Environment so everyone has the same build which is XP (service pack 3) running IE 8.
To make matters even more strange (and this is where I am really at a loss) if I make a copy of the aspx and cs file and change its name and then get the same problem machines to run the copy, it then works fine?? However I am not happy with just leaving it at that as I think this error will raise itself again as i think it may be a timing issue in terms of the event. Also we have tried restarting IIS services on the server hosting the web app.
I haven''t added too much of my code as i didn''t want to make this post too long winded and thought that any code snippets would simply reiterate what I describe above. If someone thinks my c# code would help let me know and I will send through a few more snippets of how I''m going about this.

Code snippet where I add control to session var

if ((ArrayList)Session["dynamicControlsArray"] == null)
        {
            ArrayList arr = new ArrayList();
            Session["dynamicControlsArray"] = arr;
        }
        ((ArrayList)Session["dynamicControlsArray"]).Add([nameOfControl]);



Page_load事件的代码段:



Code snippet of Page_load event:

protected void Page_Load(object sender, EventArgs e)
   {
       if (IsPostBack)
       {
           ReaddDynamicControls();
           // This method simply iterates through the above stored array and adds each back to the main panel
       }
       else
       {
           Session["dynamicControlsArray"] = null;
           PopulateForm(); // This method opens an XML file and creates radio button and checkbox lists based on the contents of it.

       }



感谢您抽出宝贵的时间阅读本文,祝您度过愉快的一天!
Danny



Thanks for taking the time to read this and have a great day!
Danny

推荐答案

在page_load和page_loadcomplete
after page_load and page_loadcomplete


这篇关于在Web应用程序的页面生命周期中,按钮单击事件发生在哪个阶段?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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