有两种类型的回发事件 [英] Two types of postback events

查看:202
本文介绍了有两种类型的回发事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


1)我发现了两篇文章,每个分类有点不同的两种类型的回发事件:

1) I found two articles, each categorizing a bit differently the two types of postback events:

一个资源说,两种类型的回发事件是的更改事件(控件实现IPostbackDataHandler),它会调用数据时回发之间变化,然后为募集事件(其中控件实现IPostbackEventHandler),这是由服务器控件引发无论出于何种原因,控制认为合适

One resource says the two types of postback events are Changed event ( where controls implement IPostbackDataHandler ), which fires when data is changed between postbacks, and then are Raised events ( where controls implement IPostbackEventHandler ), which are raised by server controls for whatever reason the control sees fit

相关文章说,两种类型的即时响应事件和​​更改事件。根据这篇文章,立即作出反应事件是那些真正触发回发

Other article says the two types are Immediate response events and Change events. According to this article, Immediate response events are ones that actually trigger a postback


A),它的分类是正确的?

a) Which categorization is correct?

b)若第二条是正确的,那么如果TextBox控件具有的AutoPostBack =true时,不应该再框TextChanged也可考虑即时响应事件?

b) If second article was correct, then if TextBox control had AutoPostBack="true", shouldn’t then TextChanged also be considered Immediate response event?


2)当页被提交回服务器由于一些用户操作,然后在事件处理阶段的,ASP.NET将引发,进行了自上次回发他们的数据更改的所有控制的事件。实际上触发回传(如Click事件)的事件前次募集

2) When page is submitted back to the server due to some user action, then at Event handling stage, ASP.NET raises events of all controls that got their data changed since the last postback. The event that actually triggered a postback ( such as Click event ) is raised last


A)但是,如果用户选择GridView的一排造成回传?当GridView控件导致由于行选择,那么不像简单的控件(如文本框或按钮)回传,这回发导致的GridView火不是一​​个,而是在事件几个服务器端事件处理阶段(SelectedIndexChaning和的SelectedIndexChanged)。

a) But what if user selecting a row in GridView caused a postback? When GridView causes a postback due to Row selection, then unlike simpler controls ( like TextBox or Button ), that postback causes GridView to fire not one, but several server-side events during Event handling stage ( SelectedIndexChaning and SelectedIndexChanged).

这些GridView的事件,这是由ASP.NET认为是造成回传的人吗?

Which of these GridView’s events is considered by ASP.NET to be the one that caused a postback?


感谢您

推荐答案

SelectedIndexChanged事件(在列表框)和TextChanged事件(上一个文本框),将火上,即使AutoPostBack属性为假回发。

The SelectedIndexChanged event (on a listbox) and the TextChanged event (on a Textbox) will fire on a postback even if the Autopostback property is false.

尝试把这样的形式:

   <asp:ListBox runat="server" ID="test" 
        onselectedindexchanged="test_SelectedIndexChanged">
<asp:ListItem >number1</asp:ListItem>
 <asp:ListItem >number2</asp:ListItem>     
</asp:ListBox>

<asp:TextBox runat="server" ID="text" ontextchanged="text_TextChanged" />
<asp:Button runat="server" Text="Click Me" />

这背后的code:

and this in the code behind:

 protected void test_SelectedIndexChanged(object sender, EventArgs e)
    {
        Response.Write("SelectedIndexChanged");
    }

    protected void text_TextChanged(object sender, EventArgs e)
    {
        Response.Write("TextChanged");
    }

然后运行它,改变所选的项目,输入一些文字,并按下按钮 - 这两个事件火。你可以看到使用反射的事件序列。对于文本框,在RaisePostDataChangedEvent方法是:

Then run it, change the selected item, type some text, and hit the button - both events fire. You can see the sequence of events using Reflector. For the Textbox, the RaisePostDataChangedEvent method is:

 protected virtual void RaisePostDataChangedEvent()
{
    if (this.AutoPostBack && !this.Page.IsPostBackEventControlRegistered)
    {
        this.Page.AutoPostBackControl = this;
        if (this.CausesValidation)
        {
            this.Page.Validate(this.ValidationGroup);
        }
    }
    this.OnTextChanged(EventArgs.Empty);
}

这篇关于有两种类型的回发事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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