Finding events to be processed in ASP.NET

倾然丶 夕夏残阳落幕 提交于 2019-12-13 06:30:38

问题


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

protected void Page_Load(object sender, EventArgs e)

Then it hits

protected void ImageButton_Click(object sender, EventArgs e)

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?


回答1:


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


来源:https://stackoverflow.com/questions/1647307/finding-events-to-be-processed-in-asp-net

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!