ASP.NET的DropDownList OnSelectedIndexChanged事件不会触发 [英] ASP.NET DropDownList OnSelectedIndexChanged event not fired

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

问题描述

我试图用一些AJAX和ASP.Net在一起,使我不必刷新整个页面运行的功能,但我已经跨越一个问题,在做这个迷迷糊糊

I'm trying to use some AJAX and ASP.Net together to enable me to run functions without having to refresh the whole page but i've stumbled across a problem in doing this

下面是我的code

<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>

<asp:UpdatePanel ID="UpdatePanel1" runat="server">
    <ContentTemplate>
        <asp:DropDownList ID="ddl1" runat="server" OnSelectedIndexChanged="update1" />

        <asp:TextBox runat="server" ID="txt1" />

    </ContentTemplate>
</asp:UpdatePanel>

这是我的code后面

And here's my code behind

 Sub update1(ByVal sender As Object, ByVal e As EventArgs)

    txt1.Text = Now.ToString

End Sub

本次活动不火,因为我没有的AutoPostBack =真在我的DDL,但补充说,到DDL将回发整个页面。

The event doesn't fire because I don't have AutoPostBack="True" on my ddl but adding that to the ddl will postback the whole page.

有没有办法避免使用的AutoPostBack =真,使其只更新面板?

Is there a way to avoid using AutoPostBack="True" so that it only updates the panel?

我知道我可以使用 ASP:按钮来解决这个问题,但我真的很想能够使用一个DDL与 OnSelectedIndexChanged

I know I can use an asp:Button to get around this but i'd really like to be able to use a ddl with OnSelectedIndexChanged

感谢

推荐答案

如果你想避免整个视图状态发送给服务器,你应该看看的回调

If you want to avoid to send the whole viewstate to the server, you should look at callbacks.

相反,如果你想避免整个页面的刷新,但回发,这应该工作:

Instead, if you want to avoid a refresh of the entire page, but with postback, this should work:

<asp:DropDownList ID="ddl1" runat="server" OnSelectedIndexChanged="update1" AutoPostBack="True"  />

<asp:UpdatePanel ID="UpdatePanel1" runat="server">
    <Triggers>
         <asp:AsyncPostbackTrigger ControlID="ddl1" EventName="SelectedIndexChanged" />
    </Triggers>
    <ContentTemplate>
        <asp:TextBox runat="server" ID="txt1" />
    </ContentTemplate>
</asp:UpdatePanel>

这篇关于ASP.NET的DropDownList OnSelectedIndexChanged事件不会触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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