每次按钮都会导致完全回发,即使它在更新面板中也是如此

时间:2013-03-19 13:04:08

标签: asp.net jquery asp.net-ajax

在我的代码中,每个DropDownList都在更新面板中,并且它们不会回发。对于每个按钮,单击完全回发,但我的按钮位于更新面板中。我尝试使用asynpostback触发器,在这种情况下,不显示服务器端消息。我也想要那条消息。

我的代码是:

<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>

1 个答案:

答案 0 :(得分:3)

我在使用Visual Studio 2010,.NET Framework 4.0的空白解决方案中尝试过您的代码。更改以下内容,我设法避免按钮的完整回发:

我为每个按钮添加了Click事件的AsyncPostBackTriger属性,为DropDownLists添加了SelectedIndexChanged。我还配置了UpdatePanel属性ChildrenAsTriggers="false"UpdateMode="Conditional"。对每个UpdatePanel采用相同的方法都可以解决问题。

<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>

我注意到按钮Schedule不在更新面板中,所以很明显它导致了整页回发。