Mahesh
Mahesh

Reputation: 1689

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. The page is behaving normal when I click btnTest button.

Could anyone let me know why this is happening??

Thanks, Mahesh

Upvotes: 3

Views: 1262

Answers (2)

AjayR
AjayR

Reputation: 4179

You should set the AutoPostback to false for dropdown list and in code,make sure you write the condition like this in Page_Load if (!isPostBack()) { // Write your code, it will work only once }

Upvotes: 0

Steve Kiss
Steve Kiss

Reputation: 1118

You need to change the AutoPostBack to False in your DropDownList.

Upvotes: 1

Related Questions