简体   繁体   English

ASP.NET页面事件调用两次

[英]ASP.NET Page events calling twice

I have code in one of my pages which is as given below: 我的一个页面中有代码,如下所示:

<asp:button id="btnTest" runat="server" onclick="btnTest_click" />
<div class="TomasForm">
        <ul>
            <li>
                <asp:Label ID="LineL" runat="server" AssociatedControlID="Lines" Text="<%$ FieldLabelResources:Units, Line, false %>" />
                <asp:DropDownList ID="Lines" runat="server" AutoPostBack="true" AppendDataBoundItems="true"
                    DataTextField="Name" DataValueField="Id" OnSelectedIndexChanged="Lines_SelectedIndexChanged">
                    <asp:ListItem Text="<%$ Resources:Common, SelectOne %>" Value="-1" />
                </asp:DropDownList >
            </li>
        </ul>
    </div>

My issue is when I change the Lines dropdownlist value, the page(page_load and Lines_SelectedIndexChanged events) is getting called twice. 我的问题是当我更改Lines下拉列表值时,页面(page_load和Lines_SelectedIndexChanged事件)被调用两次。 The page is behaving normal when I click btnTest button. 单击btnTest按钮时页面正常。

Could anyone let me know why this is happening?? 谁能让我知道为什么会这样?

Thanks, Mahesh 谢谢,马赫什

您需要在DropDownList中将AutoPostBack更改为False。

你应该为下拉列表和代码中的AutoPostback设置为false,确保你在Page_Load中编写这样的条件if(!isPostBack()){//编写代码,它只能工作一次}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM