寻找事件在ASP.NET处理 [英] Finding events to be processed in ASP.NET

查看:179
本文介绍了寻找事件在ASP.NET处理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在回传,从点击一个ImageButton的,它首先点击

On PostBack, from clicking on an ImageButton, it first hits

protected void Page_Load(object sender, EventArgs e)

然后点击

protected void ImageButton_Click(object sender, EventArgs e)

我的问题是,在我的Page_Load它刷新列表框之前选定的项目可以通过ImageButton_Click进行处理。

My problem is that in my Page_Load it refreshes a ListBox before the selected items can be processed by ImageButton_Click.

有没有办法告诉哪些事件尚未处理的,这样我就可以处理?

Is there a way to tell what events are yet to be processed, so I can handle them?

推荐答案

填充/数据绑定列表框的范围内的Page_Load,回发后不。视图状态将保持在ListBox中的项目之后。

Populate/databind your ListBox within Page_Load only on the first load, not after postback. Viewstate will maintain the items in your ListBox subsequently.

protected void Page_Load(object sender, EventArgs e) {

    if(!IsPostBack) //if not postback
    {
       //populate your listbox
    }

}

下面是页面上的生命周期一个良好的阅读,你就会明白页/儿童控件的事件及其用途的序列/顺序。

Here's a good read on the Page's Lifecycle, you'll understand the sequence/order of page/child-controls' events and their purposes.

http://msdn.microsoft.com/en-us/library/ms178472.aspx

这篇关于寻找事件在ASP.NET处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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