ASP.NET刷新UpdatePanel OnClientClick

时间:2012-01-24 04:36:14

标签: c# javascript asp.net updatepanel postback

我有几个更新面板,一个包含gridview,另一个包含detailsview。我无法在detailsview中获得一个按钮,以便能够触发gridview更新面板的更新。我已经尝试了几件事(从c#做起来也可以......)但是现在这就是我现在的......有什么建议吗? [...我需要“confirmButton”来触发“SelectCarUP”中的更新]

<asp:UpdatePanel ID="SelectCarUP" runat="server">
  <ContentTemplate>
    <asp:GridView ID="VehiclesGridView" runat="server" AllowPaging="True" 
        AllowSorting="True" DataSourceID="VehiclesEDS" 
        AutoGenerateColumns="False" 
        onselectedindexchanged="VehiclesGridView_SelectedIndexChanged" 
        BackColor="White" BorderColor="#999999" 
        BorderStyle="None" BorderWidth="1px" 
        CellPadding="3" GridLines="Vertical" ShowHeaderWhenEmpty="True">
        <AlternatingRowStyle BackColor="#DCDCDC" />
        <Columns>
           <asp:TemplateField ShowHeader="False">
              <ItemTemplate>
                 <asp:LinkButton ID="GVSelectButton" runat="server" 
                     CausesValidation="False" 
                     CommandName="Select" Text="Select"></asp:LinkButton>
              </ItemTemplate>
           </asp:TemplateField>
           <asp:BoundField DataField="CarNum" HeaderText="Car" ReadOnly="True" 
               SortExpression="CarNum" />
           <asp:BoundField DataField="CurrPassengers" HeaderText="Passengers" 
               ReadOnly="True" SortExpression="CurrPassengers" />
           <asp:BoundField DataField="MaxPassengers" HeaderText="Capacity"  
               ReadOnly="True" SortExpression="MaxPassengers" />
           <asp:BoundField DataField="Status" HeaderText="Status" 
               ReadOnly="True" SortExpression="Status" />
           <asp:BoundField DataField="StartAdd" HeaderText="Pick-Up Address" 
               ReadOnly="True" SortExpression="StartAdd" />
           <asp:BoundField DataField="EndAdd" HeaderText="Drop-Off Address" 
               ReadOnly="True" SortExpression="EndAdd" />
           <asp:BoundField DataField="AvgRideTime" HeaderText="Avg. Ride Time" 
               ReadOnly="True" SortExpression="AvgRideTime" />
        </Columns>
        <FooterStyle BackColor="#CCCCCC" ForeColor="Black" />
        <HeaderStyle BackColor="#004812" Font-Bold="True" ForeColor="White" />
        <PagerStyle BackColor="#999999" ForeColor="Black" 
           HorizontalAlign="Center" />
        <RowStyle BackColor="#EEEEEE" ForeColor="Black" />
        <SelectedRowStyle BackColor="#C6940D" Font-Bold="True" 
           ForeColor="White" />
        <SortedAscendingCellStyle BackColor="#F1F1F1" />
        <SortedAscendingHeaderStyle BackColor="#C6940D" />
        <SortedDescendingCellStyle BackColor="#CAC9C9" />
        <SortedDescendingHeaderStyle BackColor="#9F770B" />
     </asp:GridView>
  </ContentTemplate>
</asp:UpdatePanel>
<asp:Table ID="Table1" runat="server" CssClass="DefaultTable">
   <asp:TableRow runat="server">
       <asp:TableCell runat="server" Width="50%" 
           VerticalAlign="Top" HorizontalAlign="Left">
           <asp:UpdatePanel ID="detailsUP" runat="server" 
                UpdateMode="Always" ChildrenAsTriggers="True">
              <ContentTemplate>
                  <!--
                     <asp:Label ID="label1" runat="server" 
                        Text="Car To Dispatch: " CssClass="DefaultLabel">
                     </asp:Label>
                     <asp:DropDownList ID="CarsDDL" runat="server"
                        DataSourceID="VehiclesEDS" 
                        DataMember="CarNum" DataTextField="CarNum"
                        AppendDataBoundItems="True" Font-Bold="True">
                           <asp:ListItem Selected="True" Text="-">
                           </asp:ListItem>
                      </asp:DropDownList>
                  -->
                  <asp:DetailsView ID="RideToAssignDV" runat="server"
                      Height="400px" Width="400px" AutoGenerateRows="False"
                      BackColor="White" BorderColor="#999999" 
                      BorderStyle="None" BorderWidth="1px" 
                      CellPadding="3" GridLines="Vertical">
                        <AlternatingRowStyle BackColor="#DCDCDC" />
                        <EditRowStyle BackColor="#008A8C" Font-Bold="True"
                           ForeColor="White" />
                        <Fields>
                            <asp:BoundField DataField="AssignedCar" 
                                HeaderText="Car"             
                                SortExpression="AssignedCar" NullDisplayText="---" />            
                            <asp:BoundField DataField="Name" HeaderText="Name" 
                                SortExpression="Name" NullDisplayText="---" />
                            <asp:BoundField DataField="Phone" HeaderText="Phone" 
                                SortExpression="Phone" NullDisplayText="---" />
                            <asp:BoundField DataField="NumPatrons" HeaderText="Size" 
                                SortExpression="NumPatrons" NullDisplayText="---" />                
                            <asp:BoundField DataField="PickupAddress" 
                                HeaderText="Pickup Address" 
                                SortExpression="PickupAddress" NullDisplayText="---" />
                            <asp:BoundField DataField="DropoffAddress" 
                                HeaderText="Drop-Off Address" 
                                SortExpression="DropoffAddress" 
                                NullDisplayText="---" />
                            <asp:BoundField DataField="CreatedBy" 
                                HeaderText="Created By" 
                                SortExpression="CreatedBy" NullDisplayText="---" />
                            <asp:BoundField DataField="TimeOfCall" 
                                HeaderText="Call Time" 
                                SortExpression="TimeOfCall" ReadOnly="True"
                                NullDisplayText="---" />
                        </Fields>
                        <FooterStyle BackColor="#CCCCCC" ForeColor="Black"
                            BorderStyle="Inset" BorderColor="#C6940D"
                            HorizontalAlign="Center" Height="25px" />
                        <FooterTemplate>
                            <asp:Button ID="confirmButton" runat="server"
                                Text="Confirm" ForeColor="Green" 
                                HorizontalAlign="Center" OnClick="confirmButton_Click"
                                OnClientClick="refreshGV();"/>
                            <asp:Button ID="cancelButton" runat="server" Text="Cancel"
                                ForeColor="Red" HorizontalAlign="Center" 
                                OnClick="cancelButton_Click"
                                OnClientClick="displayTopTen();" />
                        </FooterTemplate>
                        <HeaderStyle BackColor="#004812" Font-Bold="True" />
                        <PagerStyle BackColor="#999999" ForeColor="Black" />
                        <RowStyle BackColor="#EEEEEE" ForeColor="Black" />                            
                 </asp:DetailsView>
          </ContentTemplate>
     </asp:UpdatePanel>
</asp:TableCell>

<script type="text/javascript">
function refreshGV() {
             __doPostBack("<%= SelectCarUP.ClientID %>", "");
         }    
</script>

1 个答案:

答案 0 :(得分:3)

尝试

ScriptManager.GetCurrent(this).RegisterAsyncPostBackControl(this.confirmButton);

参考this ASP.net forum

在代码隐藏调用SelectCarUP.Update()内的按钮单击事件处理程序中它应该更新SelectCarUP面板。有关详细信息,请参阅article on MSDN

在后面的代码中,您可以为此按钮添加触发器(不确定)

SelectCarUP.Triggers.Add(new AsyncPostBackTrigger()
{
    ControlID = confirmButton.UniqueID,
    EventName = "Click"
});

希望这适合你。