Every time button cause full post back, even it is in update panel

10,585

I've tried your code in a blank Solution, using Visual Studio 2010, .NET Framework 4.0. Changing the following, I manage to avoid the full postback from the buttons:

I've added the AsyncPostBackTriger property for the Click event for each button and SelectedIndexChanged for the DropDownLists. Also I've configured the UpdatePanel properties ChildrenAsTriggers="false" and UpdateMode="Conditional". Following the same approach for every UpdatePanel will do the trick.

<asp:UpdatePanel ID="UpdatePanel4" runat="server" ChildrenAsTriggers="false" UpdateMode="Conditional">
    <Triggers>
        <asp:AsyncPostBackTrigger ControlID="ddlTiming" EventName="SelectedIndexChanged" />
        <asp:AsyncPostBackTrigger ControlID="btnAdd" EventName="Click" />
    </Triggers>
    <ContentTemplate>

        <asp:DropDownList ID="ddlTiming" runat="server" Width="155px" Height="23px" AutoPostBack="True"
            Class="valid" OnSelectedIndexChanged="ddlTiming_SelectedIndexChanged">
        </asp:DropDownList>
        <asp:Button ID="btnAdd" runat="server" Text="Add" />
        <cc1:modalpopupextender id="btnAdd_ModalPopupExtender" runat="server" cancelcontrolid="btnCancleInsertTime"
            dynamicservicepath="" enabled="True" popupcontrolid="Panel1" targetcontrolid="btnAdd">
        </cc1:modalpopupextender>
    </ContentTemplate>
</asp:UpdatePanel>

I've noticed that the button Schedule was not inside an Update Panel, so obviously it was causing full page postback.

Share:
10,585
user2181075
Author by

user2181075

Updated on June 04, 2022

Comments

  • user2181075
    user2181075 almost 2 years

    In my code every DropDownList is inside an Update Panel and they're not postbacking. For each button click full postback occurs, but my buttons are in Update Panel. I tried using the asynpostback trigger, in that case server side message is not displayed. I want that message also.

    My code is:

    <asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
        <form id="form1" runat="server">
        <asp:ScriptManager ID="ScriptManager1" runat="server" EnablePartialRendering="true">
        </asp:ScriptManager>
        <table align="center" style="border: thin solid #FF0000" width="80%">
            <tr>
                <th colspan="2" align="center" bgcolor="Black" style="color: #FFFFFF">
                    Schedule New Batch
                </th>
            </tr>
            <tr>
                <td colspan="2" align="center">
                    <div>
                        <asp:Label ID="lblError" runat="server" Style="font-weight: 700; color: #FF0000;"
                            Text="Label" Visible="False"></asp:Label>
                        <asp:Label ID="lblSucess" runat="server" Style="font-weight: 700; color: #006600;
                            background-color: #FFFFFF;" Text="Label" Visible="False"></asp:Label>
                    </div>
                </td>
            </tr>
            <tr>
                <td colspan="2">
                    &nbsp;
                </td>
            </tr>
            <tr>
                <td class="style44" align="right">
                    Technology<span class="style23">*</span> :
                </td>
                <td class="style45">
                    <asp:UpdatePanel ID="UpdatePanel1" runat="server">
                        <ContentTemplate>
                            <asp:DropDownList ID="ddlTechnology" runat="server" Width="155px" Class="valid" OnSelectedIndexChanged="ddlTechnology_SelectedIndexChanged"
                                AutoPostBack="True" Height="23px">
                            </asp:DropDownList>
                        </ContentTemplate>
                    </asp:UpdatePanel>
                </td>
            </tr>
            <tr>
                <td class="style49" align="right">
                    Courses<span class="style23">*</span> :
                </td>
                <td class="style50">
                    <asp:UpdatePanel ID="UpdatePanel2" runat="server">
                        <ContentTemplate>
                            <asp:DropDownList ID="ddlCourse" runat="server" Width="155px" Class="valid" OnSelectedIndexChanged="ddlCourse_SelectedIndexChanged"
                                AutoPostBack="True" Height="23px">
                            </asp:DropDownList>
                        </ContentTemplate>
                    </asp:UpdatePanel>
                </td>
            </tr>
            <tr>
                <td class="style9" align="right">
                    Faculty<span class="style23">*</span> :
                </td>
                <td class="style47">
                    <asp:UpdatePanel ID="UpdatePanel3" runat="server">
                        <ContentTemplate>
                            <asp:DropDownList ID="ddlFaculty" runat="server" Width="155px" Class="valid" OnSelectedIndexChanged="ddlFaculty_SelectedIndexChanged"
                                AutoPostBack="True" Height="23px">
                            </asp:DropDownList>
                        </ContentTemplate>
                    </asp:UpdatePanel>
                </td>
            </tr>
            <tr>
                <td class="style44" align="right">
                    Timing<span class="style24">*</span> :
                </td>
                <td class="style45">
                    <asp:UpdatePanel ID="UpdatePanel4" runat="server">
                        <ContentTemplate>
                            <asp:DropDownList ID="ddlTiming" runat="server" Width="155px" Height="23px" AutoPostBack="True"
                                Class="valid" OnSelectedIndexChanged="ddlTiming_SelectedIndexChanged">
                            </asp:DropDownList>
                            <asp:Button ID="btnAdd" runat="server" Text="Add" />
                            <cc1:modalpopupextender id="btnAdd_ModalPopupExtender" runat="server" cancelcontrolid="btnCancleInsertTime"
                                dynamicservicepath="" enabled="True" popupcontrolid="Panel1" targetcontrolid="btnAdd">
                    </cc1:modalpopupextender>
                        </ContentTemplate>
                    </asp:UpdatePanel>
                </td>
            </tr>
            <tr>
                <td class="style44" align="right">
                    Start Date<span class="style23">*</span> :
                </td>
                <td class="style45">
                    <asp:UpdatePanel ID="UpdatePanel6" runat="server">
                        <ContentTemplate>
                            <asp:TextBox ID="txtInsertdate" runat="server" Width="150px" Height="16px" Class="valid"></asp:TextBox>
                            <cc1:calendarextender id="CalendarExtender1" runat="server" targetcontrolid="txtInsertdate"
                                format="yyyy-MM-dd">
                    </cc1:calendarextender>
                        </ContentTemplate>
                    </asp:UpdatePanel>
                </td>
            </tr>
            <tr>
                <td class="style51">
                    &nbsp;
                </td>
                <td class="style45">
                    &nbsp;
                </td>
            </tr>
            <tr>
                <td>
                    <div style="text-align: right">
                        <asp:Button ID="btnSchedule" runat="server" Text="Schedule" Style="font-weight: 700;
                            margin-left: 0px;" Width="81px" Height="24px" OnClick="btnSchedule_Click" />
                    </div>
                </td>
                <td>
                    <asp:UpdatePanel ID="UpdatePanel5" runat="server">
                        <ContentTemplate>
                            <asp:Button ID="btnreset" runat="server" OnClick="btnreset_Click" Style="font-weight: 700"
                                Text="Reset" Width="67px" CausesValidation="False" UseSubmitBehavior="false" />
                        </ContentTemplate>
                        <Triggers>
                            <asp:PostBackTrigger ControlID="btnreset" />
                        </Triggers>
                    </asp:UpdatePanel>
                </td>
            </tr>
            <tr>
                <td colspan="3">
                    <asp:Panel ID="Panel1" runat="server" aline="center">
                        <table style="border: thin solid #FF0000; background: #7F8778">
                            <tr>
                                <th class="style53">
                                    Please Add a Time
                                </th>
                            </tr>
                            <tr>
                                <td align="center" style="color: #FF0000" class="style53">
                                    <asp:TextBox ID="txtInsertTime" runat="server" Width="124px"></asp:TextBox>
                                    &nbsp; EX: 09:15AM
                                </td>
                            </tr>
                            <tr>
                                <asp:UpdatePanel ID="UpdatePanel7" runat="server">
                                    <ContentTemplate>
                                        <td align="center" class="style53">
                                            <asp:Button ID="btnInsertTime" runat="server" Text="Add Time" Width="73px" OnClientClick="return InsertTime()"
                                                OnClick="btnInsertTime_Click" class="cancel" />
                                            &nbsp; &nbsp;
                                            <asp:Button ID="btnCancleInsertTime" Text="Cancel" Width="55px" runat="server" class="cancel" />
                                        </td>
                                    </ContentTemplate>
                                </asp:UpdatePanel>
                            </tr>
                        </table>
                    </asp:Panel>
                </td>
            </tr>
        </table>
        <br />
        </form>
    </asp:Content>