0

我有两个 UpdatePanel,一个 UpdatePanel 包含 Grid,另一个包含数据条目。当用户单击 GridView 中的 ImageButton 时,它将显示给 ModalPopupExtender 并显示第二个 UpdatePanel。当用户将数据输入到第二个 UpdatePanel 下的字段中时,如果他们单击按钮报告或按钮取消,我将在两个按钮上强制回发。问题是,如果用户返回并单击页面上的不同行,则未清除 UpdatePanel2 下的所有数据单击的第一行中的所有数据...我尝试过 UpdatePanel1.Update(),UpdatePanel2.Update( ) 整页 PostBack 没有任何作用。唯一有效的方法是如果我将 Response.Redirect 返回到自身。但我试图避免这样做,并试图避免使用 .cs 代码将字段清除为空。想知道是否有办法回发并清除 UpdatePanel2 下的所有字段。提前感谢您的帮助。

<asp:UpdatePanel ID="upGrid" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<div>
    <span id="lblTab" runat="server" style=" font-weight:bold; font-size:larger">All Published Reports</span>
    <br />      
    <asp:GridView 
            ID="gvReports" 
            runat="server" 
            CssClass="gridview" 
            RowStyle-CssClass="gridview_itm" 
            AlternatingRowStyle-CssClass="gridview_aitm" 
            HeaderStyle-CssClass="gridview_hdr" 
            PagerStyle-CssClass="gridview_pgr" 
            AutoGenerateColumns="False" 
            Width="100%" onrowcommand="gvReports_RowCommand">                
            <Columns>
            <asp:TemplateField HeaderText="Name">                    
                <ItemTemplate>                        
                    <asp:LinkButton ID="btnReport" runat="server" CommandName="Report" CommandArgument='<%#Eval("n_ReportFileName")%>' Text='<%#Eval("n_Name")%>' CausesValidation="false"></asp:LinkButton>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="Name">                    
                <ItemTemplate>                        
                    <%#Eval("n_Description")%>
                </ItemTemplate>
            </asp:TemplateField>
            </Columns>
    </asp:GridView>                                         
    <asp:UpdatePanel ID="UpdatePanel1" runat="server">
        <ContentTemplate>
            <asp:ModalPopupExtender ID="ModalPopupExtender1" runat="server" TargetControlID="Button1" PopupControlID="ReportParameterPanel" BackgroundCssClass="modalBackground" DropShadow="True">
            </asp:ModalPopupExtender>
            <asp:Button ID="Button1" runat="server" Text="Button" style="visibility:hidden"/>
            <asp:Panel ID="ReportParameterPanel" runat="server" Height="375px" 
                Width="700px" BackColor="#f4de90" 
                HorizontalAlign="Center" BorderColor="#666666" BorderStyle="Outset" 
                BorderWidth="5px"> 
                <table style="height: 50px; width: 685px; text-align: left">
                    <span id="lblReportName" runat="server" style="font-weight:bold; font-size:larger"></span>
                    <tr>
                        <td align="left" style="padding-left: 5px; width: 335px;" valign="top">
                            <span id="StarDateStar" runat="server" style="color: Red">*Optional&nbsp;</span><span id="lblStartDate" runat="server">Start Date: </span>
                            <asp:TextBox ID="tbStartDate" runat="server"></asp:TextBox>
                            <asp:ImageButton ID="imgCalendar" runat="server" ImageUrl="~/App_Themes/Sugar2006/images/Calendar_scheduleHS.png" ImageAlign="Middle" />
                            <asp:CalendarExtender ID="ceStartDate" runat="server" TargetControlID ="tbStartDate" PopupButtonID="imgCalendar" />        
                            <asp:MaskedEditExtender ID="mexStartDate" runat="server" 
                                TargetControlID="tbStartDate" 
                                Mask="99/99/9999" 
                                MaskType="Date"
                                MessageValidatorTip="true"
                                OnFocusCssClass="MaskedEditFocus"
                                OnInvalidCssClass="MaskedEditError" />
                                <br />
                            <asp:MaskedEditValidator ID="mevStartDate" runat="server" 
                                ControlToValidate="tbStartDate"
                                ControlExtender="mexStartDate" 
                                Display="Dynamic" 
                                InvalidValueMessage="This date is invalid!" Font-Bold="True" 
                                ForeColor="#D50000" ValidationGroup="vgMyGroup" />
                        </td>
                        <td align="left" style="padding-right: 5px; padding-bottom: 5px; width: 350px;" valign="top">
                            <span id="EndDateStar" runat="server" style="color: Red">*Optional&nbsp;</span><span id="lblEndDate" runat="server">End Date: </span>
                            <asp:TextBox ID="tbEndDate" runat="server"></asp:TextBox>
                            <asp:ImageButton ID="imgCalendar2" runat="server" ImageUrl="~/App_Themes/Sugar2006/images/Calendar_scheduleHS.png" ImageAlign="Middle" />
                            <asp:CalendarExtender ID="ceEndDate" runat="server" TargetControlID ="tbEndDate" PopupButtonID="imgCalendar2" />        
                            <asp:MaskedEditExtender ID="mexEndDate" runat="server" 
                                TargetControlID="tbEndDate" 
                                Mask="99/99/9999" 
                                MaskType="Date"
                                MessageValidatorTip="true"
                                OnFocusCssClass="MaskedEditFocus"
                                OnInvalidCssClass="MaskedEditError" />
                                <br />
                            <asp:MaskedEditValidator ID="mevEndDate" runat="server" 
                                ControlToValidate="tbEndDate"
                                ControlExtender="mexEndDate" 
                                Display="Dynamic" 
                                InvalidValueMessage="This date is invalid!" Font-Bold="True" 
                                ForeColor="#D50000"
                                ValidationGroup="vgMyGroup" />
                        </td>
                    </tr>
                </table> 

                <table style="height: 25px; width: 685px; text-align: left">
                    <tr>
                        <td align="left" style="padding-left: 5px; width: 335px;" valign="top">
                            <span id="lblOperator" runat="server">Operator:</span>
                            <asp:DropDownList ID="Parameters" runat="server" style="margin-left: 73px">
                                <asp:ListItem Selected="True"><</asp:ListItem>
                                <asp:ListItem>></asp:ListItem>
                                <asp:ListItem>=</asp:ListItem>
                                <asp:ListItem>Completed</asp:ListItem>
                                <asp:ListItem>Not Completed</asp:ListItem>
                            </asp:DropDownList>
                        </td>
                    </tr>
                </table> 

                <asp:RadioButtonList ID="GroupingList" runat="server" Height="25px" 
                        RepeatDirection="Horizontal" 
                        AutoPostBack="true" onselectedindexchanged="GroupingList_SelectedIndexChanged" 
                         CausesValidation="true" ValidationGroup="vgMyGroup" /> 

                <table style="height: 25px; width: 685px; text-align: left">
                    <tr id="rowEntitySelectionLabels" runat="server">
                        <td style="padding-left: 3px; height: 16px; width: 300px;">
                            <asp:Label ID="GroupItemInputLabel" runat="server" />
                        </td>
                        <td style="height: 16px; width: 48px;">
                        </td>
                        <td style="height: 16px; width: 300px;">
                            <asp:Label ID="GroupItemsListInputLabel" runat="server" />
                        </td>
                    </tr>
                    <tr id="rowEntitySelections" runat="server">
                        <td valign="top" style="padding-left: 3px; height: 100px; width: 300px;">
                            <asp:ListBox ID="GroupItemInput" runat="server" Width="300px" Height="150px" 
                                SelectionMode="multiple" BackColor="White" ForeColor="Black" />
                        </td>
                        <td align="center" valign="top" style="height: 100px; width: 50px;">
                        <br />
                            <asp:ImageButton ID="btnAddItem" 
                                ImageUrl="~/App_Themes/Sugar2006/images/Actions-arrow-right-icon.png" runat="server" 
                                OnClick="btnAddItem_Click" Height="18px" Width="25px" 
                                ToolTip="Adds the Selected <Item>." CausesValidation="true" ValidationGroup="vgMyGroup" /><br />
                            <asp:ImageButton ID="btnAddAllItems"                                     
                                ImageUrl="~/App_Themes/Sugar2006/images/Actions-arrow-right-double-icon.png" runat="server" 
                                OnClick="btnAddAllItems_Click" Height="18px" Width="25px" 
                                ToolTip="Adds all of the <Items>." CausesValidation="true" ValidationGroup="vgMyGroup" /><br />
                            <br /><br />
                            <asp:ImageButton ID="btnRemoveItem" 
                                ImageUrl="~/App_Themes/Sugar2006/images/Actions-arrow-left-icon.png" runat="server" 
                                OnClick="btnRemoveItem_Click" Height="18px" Width="25px" 
                                ToolTip="Removes the Selected <Item>." CausesValidation="true" ValidationGroup="vgMyGroup" /><br />
                            <asp:ImageButton ID="btnRemoveAllItems"                                     
                                ImageUrl="~/App_Themes/Sugar2006/images/Actions-arrow-left-double-icon.png" runat="server" 
                                OnClick="btnRemoveAllItems_Click" Height="18px" Width="25px" 
                                ToolTip="Removes all of the <Items>." CausesValidation="true" ValidationGroup="vgMyGroup" />
                        </td>
                        <td valign="top" style="height: 100px; width: 300px;" id="TD1">
                            <asp:ListBox ID="GroupItemsList" runat="server" Width="300px" Height="150px" 
                                SelectionMode="multiple" BackColor="White" ForeColor="Black" />
                        </td>
                    </tr>
                </table>
                <asp:Button ID="btnClose" runat="server" Text="Close" CssClass="btn" onclick="btnClose_Click" CausesValidation="false" />
                <asp:Button ID="btnSend" runat="server" Text="Report" CssClass="btn" OnClick="btnSend_Click" Enabled="false" CausesValidation="true" ValidationGroup="vgMyGroup" />                    
            </asp:Panel>                                    
        </ContentTemplate>
        <Triggers>
            <asp:PostBackTrigger ControlID="btnSend" />
            <asp:PostBackTrigger ControlID="btnClose" />
        </Triggers>
    </asp:UpdatePanel>
</div>
</ContentTemplate>
</asp:UpdatePanel>
4

1 回答 1

0

尝试将 UpdatePanel.UpdateMode 属性设置为 Conditional

<asp:UpdatePanel ID="UpdatePanel1" UpdateMode="Conditional" runat="server">
    <!-- other stuff -->
</asp:UpdatePanel>

如果更新模式未设置为条件,则子更新面板将仅刷新其子项,而不是其父项。

这里还有一些更新更新面板的方法:http: //lisazhou.wordpress.com/2008/01/07/update-panel-different-ways-of-triggering-udates/

于 2012-04-06T21:49:15.997 回答