首先,我的程序效果很好,它可以做我想做的事情,我只是想避免刷新。
所以我尝试了几种不同的解决方案,但是我的更新面板似乎仍然无效。我有2个网格视图和2个表单视图。我尝试添加触发器,在方法上调用updatepanel1.update(),在每个文本框中添加autopostback ='true'等等。我将它们全部放在我的程序中只是为了尝试缩小到实际上会让我看到gridview的新内容从formview上的插入记录而不刷新页面。如果有人仍然可以让我知道我错过了什么,那就太好了。我只是要复制我的整个2个文件。
代码背后:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace PO_1_5_15
{
public partial class _Webform : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (FormView1.CurrentMode == FormViewMode.Edit)
{
LinkButton lb = (LinkButton)FormView1.FindControl("UpdateButton");
ScriptManager.GetCurrent(Page).RegisterPostBackControl(lb);
}
if (FormView1.CurrentMode == FormViewMode.Insert)
{
LinkButton lb2 = (LinkButton)FormView1.FindControl("InsertButton");
ScriptManager.GetCurrent(Page).RegisterPostBackControl(lb2);
}
if (FormView2.CurrentMode == FormViewMode.Edit)
{
LinkButton lb3 = (LinkButton)FormView1.FindControl("UpdateButton");
ScriptManager.GetCurrent(Page).RegisterPostBackControl(lb3);
}
if (FormView2.CurrentMode == FormViewMode.Insert)
{
LinkButton lb4 = (LinkButton)FormView1.FindControl("InsertButton");
ScriptManager.GetCurrent(Page).RegisterPostBackControl(lb4);
}
GridView1.DataBind();
GridView1.Visible = true;
}
protected void FormsView1_ItemInserted(object sender, DetailsViewInsertedEventArgs e)
{
GridView1.DataBind();
UpdatePanel1.Update();
}
protected void FormsView1_ItemDeleted(object sender, DetailsViewDeletedEventArgs e)
{
GridView1.DataBind();
UpdatePanel1.Update();
}
protected void FormsView1_ItemUpdated(object sender, DetailsViewUpdatedEventArgs e)
{
GridView1.DataBind();
FormView1.Visible = true;
GridView1.Visible = true;
UpdatePanel1.Update();
}
protected void GridView1_OnSelectedIndexChanged(object sender, EventArgs e)
{
FormView1.DataBind();
FormView1.Visible = true;
GridView1.Visible = false;
UpdatePanel1.Update();
}
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
GridView1.PageIndex = e.NewPageIndex;
UpdatePanel1.Update();
}
protected void FormView2_PageIndexChanging(object sender, FormViewPageEventArgs e)
{
UpdatePanel1.Update();
}
}
}
HTML标记:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Webform.aspx.cs" Inherits="PO_1_5_15._Webform" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager runat="server" ID="sm1"></asp:ScriptManager>
<div>
<br />
<asp:UpdatePanel runat="server" UpdateMode="Always" ID="UpdatePanel1">
<ContentTemplate >
<asp:GridView ID="GridView1" runat="server" AllowPaging="True" AllowSorting="True" AutoGenerateColumns="False" DataKeyNames="PO_ID" DataSourceID="SqlDataSource1" EnableModelValidation="True" BackColor="White" BorderColor="#CCCCCC" BorderStyle="None" BorderWidth="1px" CellPadding="4" ForeColor="Black" GridLines="Horizontal">
<Columns>
<asp:CommandField ShowSelectButton="True" />
<asp:BoundField DataField="PO_ID" HeaderText="PO_ID" SortExpression="PO_ID" />
<asp:BoundField DataField="PO_Title" HeaderText="PO_Title" SortExpression="PO_Title" />
<asp:BoundField DataField="Date_Received" HeaderText="Date_Received" SortExpression="Date_Received" />
<asp:BoundField DataField="Date_Completed" HeaderText="Date_Completed" SortExpression="Date_Completed" />
<asp:BoundField DataField="Username" HeaderText="Username" SortExpression="Username" />
<asp:BoundField DataField="PO_Note" HeaderText="PO_Note" SortExpression="PO_Note" />
<asp:BoundField DataField="UserDate" HeaderText="UserDate" SortExpression="UserDate" />
</Columns>
<FooterStyle BackColor="#CCCC99" ForeColor="Black" />
<HeaderStyle BackColor="#333333" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="White" ForeColor="Black" HorizontalAlign="Right" />
<SelectedRowStyle BackColor="#CC3333" Font-Bold="True" ForeColor="White" />
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:Test_DatabaseConnectionString %>" SelectCommand="SELECT [PO_ID], [PO_Title], [Date_Received], [Date_Completed], [Username], [PO_Note], [UserDate] FROM [PO_Table]"></asp:SqlDataSource>
<asp:FormView ID="FormView1" runat="server" DataKeyNames="PO_AutoID" DataSourceID="SqlDataSource2" EnableModelValidation="True" BackColor="White" BorderColor="#CCCCCC" BorderStyle="None" BorderWidth="1px" CellPadding="4" ForeColor="Black" GridLines="Horizontal">
<EditItemTemplate>
PO_AutoID:
<asp:Label ID="PO_AutoIDLabel1" runat="server" Text='<%# Eval("PO_AutoID") %>' />
<br />
PO_ID:
<asp:TextBox ID="PO_IDTextBox" runat="server" Text='<%# Bind("PO_ID") %>' AutoPostBack="True" />
<br />
PO_Title:
<asp:TextBox ID="PO_TitleTextBox" runat="server" Text='<%# Bind("PO_Title") %>' AutoPostBack="True"/>
<br />
Date_Received:
<asp:TextBox ID="Date_ReceivedTextBox" runat="server" Text='<%# Bind("Date_Received") %>' AutoPostBack="True"/>
<br />
Date_Completed:
<asp:TextBox ID="Date_CompletedTextBox" runat="server" Text='<%# Bind("Date_Completed") %>' AutoPostBack="True"/>
<br />
PO_Note:
<asp:TextBox ID="PO_NoteTextBox" runat="server" Text='<%# Bind("PO_Note") %>' AutoPostBack="True"/>
<br />
<asp:LinkButton ID="UpdateButton" runat="server" CausesValidation="True" CommandName="Update" Text="Update" />
<asp:LinkButton ID="UpdateCancelButton" runat="server" CausesValidation="False" CommandName="Cancel" Text="Cancel" />
</EditItemTemplate>
<EditRowStyle BackColor="#CC3333" Font-Bold="True" ForeColor="White" />
<FooterStyle BackColor="#CCCC99" ForeColor="Black" />
<HeaderStyle BackColor="#333333" Font-Bold="True" ForeColor="White" />
<InsertItemTemplate>
PO_ID:
<asp:TextBox ID="PO_IDTextBox" runat="server" Text='<%# Bind("PO_ID") %>' AutoPostBack="True"/>
<br />
PO_Title:
<asp:TextBox ID="PO_TitleTextBox" runat="server" Text='<%# Bind("PO_Title") %>' AutoPostBack="True"/>
<br />
Date_Received:
<asp:TextBox ID="Date_ReceivedTextBox" runat="server" Text='<%# Bind("Date_Received") %>' AutoPostBack="True"/>
<br />
Date_Completed:
<asp:TextBox ID="Date_CompletedTextBox" runat="server" Text='<%# Bind("Date_Completed") %>' AutoPostBack="True"/>
<br />
PO_Note:
<asp:TextBox ID="PO_NoteTextBox" runat="server" Text='<%# Bind("PO_Note") %>' AutoPostBack="True"/>
<br />
<asp:LinkButton ID="InsertButton" runat="server" CausesValidation="True" CommandName="Insert" Text="Insert" />
<asp:LinkButton ID="InsertCancelButton" runat="server" CausesValidation="False" CommandName="Cancel" Text="Cancel" />
</InsertItemTemplate>
<ItemTemplate>
PO_AutoID:
<asp:Label ID="PO_AutoIDLabel" runat="server" Text='<%# Eval("PO_AutoID") %>' />
<br />
PO_ID:
<asp:Label ID="PO_IDLabel" runat="server" Text='<%# Bind("PO_ID") %>' />
<br />
PO_Title:
<asp:Label ID="PO_TitleLabel" runat="server" Text='<%# Bind("PO_Title") %>' />
<br />
Date_Received:
<asp:Label ID="Date_ReceivedLabel" runat="server" Text='<%# Bind("Date_Received") %>' />
<br />
Date_Completed:
<asp:Label ID="Date_CompletedLabel" runat="server" Text='<%# Bind("Date_Completed") %>' />
<br />
Username:
<asp:Label ID="UsernameLabel" runat="server" Text='<%# Bind("Username") %>' />
<br />
UserDate:
<asp:Label ID="UserDateLabel" runat="server" Text='<%# Bind("UserDate") %>' />
<br />
PO_Note:
<asp:Label ID="PO_NoteLabel" runat="server" Text='<%# Bind("PO_Note") %>' />
<br />
<asp:LinkButton ID="EditButton" runat="server" CausesValidation="False" CommandName="Edit" Text="Edit" />
<asp:LinkButton ID="DeleteButton" runat="server" CausesValidation="False" CommandName="Delete" Text="Delete" />
<asp:LinkButton ID="NewButton" runat="server" CausesValidation="False" CommandName="New" Text="New" />
</ItemTemplate>
<PagerStyle BackColor="White" ForeColor="Black" HorizontalAlign="Right" />
</asp:FormView>
<asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:Test_DatabaseConnectionString %>" DeleteCommand="DeletePO" DeleteCommandType="StoredProcedure" InsertCommand="InsertPO" InsertCommandType="StoredProcedure" SelectCommand="SELECT * FROM [PO_Table] WHERE ([PO_ID] = @PO_ID)" UpdateCommand="UpdatePO" UpdateCommandType="StoredProcedure">
<DeleteParameters>
<asp:Parameter Name="PO_AutoID" Type="Int32" />
</DeleteParameters>
<InsertParameters>
<asp:Parameter Name="PO_ID" Type="Int32" />
<asp:Parameter Name="PO_Title" Type="String" />
<asp:Parameter Name="Date_Received" Type="DateTime" />
<asp:Parameter Name="Date_Completed" Type="DateTime" />
<asp:Parameter Name="PO_Note" Type="String" />
<asp:Parameter Name="Username" Type="String" />
<asp:Parameter Name="UserDate" Type="DateTime" />
</InsertParameters>
<SelectParameters>
<asp:ControlParameter ControlID="GridView1" Name="PO_ID" PropertyName="SelectedValue" />
</SelectParameters>
<UpdateParameters>
<asp:Parameter Name="PO_ID" Type="Int32" />
<asp:Parameter Name="PO_Title" Type="String" />
<asp:Parameter Name="Date_Received" Type="DateTime" />
<asp:Parameter Name="Date_Completed" Type="DateTime" />
<asp:Parameter Name="UserDate" Type="DateTime" />
<asp:Parameter Name="Username" Type="String" />
<asp:Parameter Name="PO_Note" Type="String" />
<asp:Parameter Name="PO_AutoID" Type="Int32" />
</UpdateParameters>
</asp:SqlDataSource>
<asp:GridView ID="GridView2" runat="server" AllowPaging="True" AllowSorting="True" AutoGenerateColumns="False" DataKeyNames="Task_AutoID" DataSourceID="SqlDataSource3" EnableModelValidation="True" BackColor="White" BorderColor="#CCCCCC" BorderStyle="None" BorderWidth="1px" CellPadding="4" ForeColor="Black" GridLines="Horizontal">
<Columns>
<asp:CommandField ShowSelectButton="True" />
<asp:BoundField DataField="Task_AutoID" HeaderText="Task_AutoID" InsertVisible="False" ReadOnly="True" SortExpression="Task_AutoID" />
<asp:BoundField DataField="PO_AutoID" HeaderText="PO_AutoID" SortExpression="PO_AutoID" />
<asp:BoundField DataField="PO_ID" HeaderText="PO_ID" SortExpression="PO_ID" />
<asp:BoundField DataField="Task_Title" HeaderText="Task_Title" SortExpression="Task_Title" />
<asp:BoundField DataField="Username" HeaderText="Username" SortExpression="Username" />
<asp:BoundField DataField="UserDate" HeaderText="UserDate" SortExpression="UserDate" />
<asp:BoundField DataField="Cost" HeaderText="Cost" SortExpression="Cost" />
<asp:BoundField DataField="_Status" HeaderText="_Status" SortExpression="_Status" />
<asp:BoundField DataField="Invoice_Date" HeaderText="Invoice_Date" SortExpression="Invoice_Date" />
<asp:BoundField DataField="Paid_Date" HeaderText="Paid_Date" SortExpression="Paid_Date" />
<asp:BoundField DataField="Task_Note" HeaderText="Task_Note" SortExpression="Task_Note" />
</Columns>
<FooterStyle BackColor="#CCCC99" ForeColor="Black" />
<HeaderStyle BackColor="#333333" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="White" ForeColor="Black" HorizontalAlign="Right" />
<SelectedRowStyle BackColor="#CC3333" Font-Bold="True" ForeColor="White" />
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource3" runat="server" ConnectionString="<%$ ConnectionStrings:Test_DatabaseConnectionString %>" SelectCommand="SELECT * FROM [Task]"></asp:SqlDataSource>
<br />
<asp:FormView ID="FormView2" runat="server" DataKeyNames="Task_AutoID" DataSourceID="SqlDataSource4" EnableModelValidation="True" OnPageIndexChanging="FormView2_PageIndexChanging" BackColor="White" BorderColor="#CCCCCC" BorderStyle="None" BorderWidth="1px" CellPadding="4" ForeColor="Black" GridLines="Horizontal">
<EditItemTemplate>
Task_AutoID:
<asp:Label ID="Task_AutoIDLabel1" runat="server" Text='<%# Eval("Task_AutoID") %>' />
<br />
PO_ID:
<asp:TextBox ID="PO_IDTextBox" runat="server" Text='<%# Bind("PO_ID") %>' AutoPostBack="True"/>
<br />
Task_Title:
<asp:TextBox ID="Task_TitleTextBox" runat="server" Text='<%# Bind("Task_Title") %>' AutoPostBack="True"/>
<br />
Cost:
<asp:TextBox ID="CostTextBox" runat="server" Text='<%# Bind("Cost") %>' AutoPostBack="True"/>
<br />
_Status:
<asp:DropDownList ID="DropDownList1" runat="server" SelectedValue='<%# Bind("_Status") %>' AutoPostBack="True">
<asp:ListItem>One</asp:ListItem>
<asp:ListItem>Two</asp:ListItem>
<asp:ListItem>Three</asp:ListItem>
</asp:DropDownList>
<br />
Invoice_Date:
<asp:TextBox ID="Invoice_DateTextBox" runat="server" Text='<%# Bind("Invoice_Date") %>' AutoPostBack="True"/>
<br />
Paid_Date:
<asp:TextBox ID="Paid_DateTextBox" runat="server" Text='<%# Bind("Paid_Date") %>' AutoPostBack="True"/>
<br />
Task_Note:
<asp:TextBox ID="Task_NoteTextBox" runat="server" Text='<%# Bind("Task_Note") %>' AutoPostBack="True"/>
<br />
<asp:LinkButton ID="UpdateButton" runat="server" CausesValidation="True" CommandName="Update" Text="Update" />
<asp:LinkButton ID="UpdateCancelButton" runat="server" CausesValidation="False" CommandName="Cancel" Text="Cancel" />
</EditItemTemplate>
<EditRowStyle BackColor="#CC3333" Font-Bold="True" ForeColor="White" />
<FooterStyle BackColor="#CCCC99" ForeColor="Black" />
<HeaderStyle BackColor="#333333" Font-Bold="True" ForeColor="White" />
<InsertItemTemplate>
PO_ID:
<asp:TextBox ID="PO_IDTextBox" runat="server" Text='<%# Bind("PO_ID") %>' AutoPostBack="True"/>
<br />
Task_Title:
<asp:TextBox ID="Task_TitleTextBox" runat="server" Text='<%# Bind("Task_Title") %>' AutoPostBack="True"/>
<br />
Cost:
<asp:TextBox ID="CostTextBox" runat="server" Text='<%# Bind("Cost") %>' AutoPostBack="True"/>
<br />
_Status:
<asp:DropDownList ID="DropDownList1" runat="server" SelectedValue='<%# Bind("_Status") %>' AutoPostBack="True">
<asp:ListItem>One</asp:ListItem>
<asp:ListItem>Two</asp:ListItem>
<asp:ListItem>Three</asp:ListItem>
</asp:DropDownList>
<br />
Invoice_Date:
<asp:TextBox ID="Invoice_DateTextBox" runat="server" Text='<%# Bind("Invoice_Date") %>' AutoPostBack="True"/>
<br />
Paid_Date:
<asp:TextBox ID="Paid_DateTextBox" runat="server" Text='<%# Bind("Paid_Date") %>' AutoPostBack="True"/>
<br />
Task_Note:
<asp:TextBox ID="Task_NoteTextBox" runat="server" Text='<%# Bind("Task_Note") %>' AutoPostBack="True"/>
<br />
<asp:LinkButton ID="InsertButton" runat="server" CausesValidation="True" CommandName="Insert" Text="Insert" />
<asp:LinkButton ID="InsertCancelButton" runat="server" CausesValidation="False" CommandName="Cancel" Text="Cancel" />
</InsertItemTemplate>
<ItemTemplate>
Task_AutoID:
<asp:Label ID="Task_AutoIDLabel" runat="server" Text='<%# Eval("Task_AutoID") %>' />
<br />
PO_AutoID:
<asp:Label ID="PO_AutoIDLabel" runat="server" Text='<%# Bind("PO_AutoID") %>' />
<br />
PO_ID:
<asp:Label ID="PO_IDLabel" runat="server" Text='<%# Bind("PO_ID") %>' />
<br />
Task_Title:
<asp:Label ID="Task_TitleLabel" runat="server" Text='<%# Bind("Task_Title") %>' />
<br />
Username:
<asp:Label ID="UsernameLabel" runat="server" Text='<%# Bind("Username") %>' />
<br />
UserDate:
<asp:Label ID="UserDateLabel" runat="server" Text='<%# Bind("UserDate") %>' />
<br />
Cost:
<asp:Label ID="CostLabel" runat="server" Text='<%# Bind("Cost") %>' />
<br />
_Status:
<asp:Label ID="_StatusLabel" runat="server" Text='<%# Bind("_Status") %>' />
<br />
Invoice_Date:
<asp:Label ID="Invoice_DateLabel" runat="server" Text='<%# Bind("Invoice_Date") %>' />
<br />
Paid_Date:
<asp:Label ID="Paid_DateLabel" runat="server" Text='<%# Bind("Paid_Date") %>' />
<br />
Task_Note:
<asp:Label ID="Task_NoteLabel" runat="server" Text='<%# Bind("Task_Note") %>' />
<br />
<asp:LinkButton ID="EditButton" runat="server" CausesValidation="False" CommandName="Edit" Text="Edit" />
<asp:LinkButton ID="DeleteButton" runat="server" CausesValidation="False" CommandName="Delete" Text="Delete" />
<asp:LinkButton ID="NewButton" runat="server" CausesValidation="False" CommandName="New" Text="New" />
</ItemTemplate>
<PagerStyle BackColor="White" ForeColor="Black" HorizontalAlign="Right" />
</asp:FormView>
<asp:SqlDataSource ID="SqlDataSource4" runat="server" ConnectionString="<%$ ConnectionStrings:Test_DatabaseConnectionString %>" DeleteCommand="DELETE FROM [Task] WHERE [Task_AutoID] = @Task_AutoID" InsertCommand="INSERT INTO [Task] ([PO_AutoID], [PO_ID], [Task_Title], [Username], [UserDate], [Cost], [_Status], [Invoice_Date], [Paid_Date], [Task_Note]) VALUES (@PO_AutoID, @PO_ID, @Task_Title, SUSER_SNAME(), SYSDATETIME(), @Cost, @_Status, @Invoice_Date, @Paid_Date, @Task_Note);
" SelectCommand="SELECT * FROM [Task] WHERE ([Task_AutoID] = @Task_AutoID)" UpdateCommand="UPDATE [Task] SET [PO_AutoID] = @PO_AutoID, [PO_ID] = @PO_ID, [Task_Title] = @Task_Title, [Username] = SUSER_SNAME(), [UserDate] = SYSDATETIME(), [Cost] = @Cost, [_Status] = @_Status, [Invoice_Date] = @Invoice_Date, [Paid_Date] = @Paid_Date, [Task_Note] = @Task_Note WHERE [Task_AutoID] = @Task_AutoID
">
<DeleteParameters>
<asp:Parameter Name="Task_AutoID" Type="Int32" />
</DeleteParameters>
<InsertParameters>
<asp:Parameter Name="PO_AutoID" Type="Int32" />
<asp:Parameter Name="PO_ID" Type="Int32" />
<asp:Parameter Name="Task_Title" Type="String" />
<asp:Parameter Name="Cost" Type="Decimal" />
<asp:Parameter Name="_Status" />
<asp:Parameter Name="Invoice_Date" Type="DateTime" />
<asp:Parameter Name="Paid_Date" Type="DateTime" />
<asp:Parameter Name="Task_Note" Type="String" />
</InsertParameters>
<SelectParameters>
<asp:ControlParameter ControlID="GridView2" Name="Task_AutoID" PropertyName="SelectedValue" Type="Int32" />
</SelectParameters>
<UpdateParameters>
<asp:Parameter Name="PO_AutoID" Type="Int32" />
<asp:Parameter Name="PO_ID" Type="Int32" />
<asp:Parameter Name="Task_Title" Type="String" />
<asp:Parameter Name="Cost" Type="Decimal" />
<asp:Parameter Name="_Status" />
<asp:Parameter Name="Invoice_Date" Type="DateTime" />
<asp:Parameter Name="Paid_Date" Type="DateTime" />
<asp:Parameter Name="Task_Note" Type="String" />
<asp:Parameter Name="Task_AutoID" Type="Int32" />
</UpdateParameters>
</asp:SqlDataSource>
<br />
<br />
<br />
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="FormView1" EventName="DataBound" />
<asp:AsyncPostBackTrigger ControlID="FormView1" EventName="DataBinding" />
<asp:AsyncPostBackTrigger ControlID="FormView1" EventName="Disposed" />
<asp:AsyncPostBackTrigger ControlID="FormView1" EventName="Init" />
<asp:AsyncPostBackTrigger ControlID="FormView1" EventName="ItemCommand" />
<asp:AsyncPostBackTrigger ControlID="FormView1" EventName="ItemCreated" />
<asp:AsyncPostBackTrigger ControlID="FormView1" EventName="ItemDeleted" />
<asp:AsyncPostBackTrigger ControlID="FormView1" EventName="ItemDeleting" />
<asp:AsyncPostBackTrigger ControlID="FormView1" EventName="ItemInserted" />
<asp:AsyncPostBackTrigger ControlID="FormView1" EventName="ItemInserting" />
<asp:AsyncPostBackTrigger ControlID="FormView1" EventName="ItemUpdated" />
<asp:AsyncPostBackTrigger ControlID="FormView1" EventName="ItemUpdating" />
<asp:AsyncPostBackTrigger ControlID="FormView1" EventName="Load" />
<asp:AsyncPostBackTrigger ControlID="FormView1" EventName="ModeChanged" />
<asp:AsyncPostBackTrigger ControlID="FormView1" EventName="ModeChanging" />
<asp:AsyncPostBackTrigger ControlID="FormView1" EventName="PageIndexChanged" />
<asp:AsyncPostBackTrigger ControlID="FormView1" EventName="PageIndexChanging" />
<asp:AsyncPostBackTrigger ControlID="FormView1" EventName="PreRender" />
<asp:AsyncPostBackTrigger ControlID="FormView1" EventName="Unload" />
<asp:AsyncPostBackTrigger ControlID="FormView2" EventName="DataBinding" />
<asp:AsyncPostBackTrigger ControlID="FormView2" EventName="DataBound" />
<asp:AsyncPostBackTrigger ControlID="FormView2" EventName="Disposed" />
<asp:AsyncPostBackTrigger ControlID="FormView2" EventName="Init" />
<asp:AsyncPostBackTrigger ControlID="FormView2" EventName="ItemCommand" />
<asp:AsyncPostBackTrigger ControlID="FormView2" EventName="ItemCreated" />
<asp:AsyncPostBackTrigger ControlID="FormView2" EventName="ItemDeleted" />
<asp:AsyncPostBackTrigger ControlID="FormView2" EventName="ItemDeleting" />
<asp:AsyncPostBackTrigger ControlID="FormView2" EventName="ItemInserted" />
<asp:AsyncPostBackTrigger ControlID="FormView2" EventName="ItemInserting" />
<asp:AsyncPostBackTrigger ControlID="FormView2" EventName="ItemUpdated" />
<asp:AsyncPostBackTrigger ControlID="FormView2" EventName="ItemUpdating" />
<asp:AsyncPostBackTrigger ControlID="FormView2" EventName="Load" />
<asp:AsyncPostBackTrigger ControlID="FormView2" EventName="ModeChanged" />
<asp:AsyncPostBackTrigger ControlID="FormView2" EventName="ModeChanging" />
<asp:AsyncPostBackTrigger ControlID="FormView2" EventName="PageIndexChanged" />
<asp:AsyncPostBackTrigger ControlID="FormView2" EventName="PageIndexChanging" />
<asp:AsyncPostBackTrigger ControlID="FormView2" EventName="PreRender" />
<asp:AsyncPostBackTrigger ControlID="GridView1" EventName="Unload" />
</Triggers>
</asp:UpdatePanel>
</div>
</form>
</body>
</html>
答案 0 :(得分:0)
这里的代码太多了。回发的目的是将更改的表单数据提交到服务器。这需要恰好发生一次,而不是每次用户更改字段时都会发生。
您必须意识到,即使使用UpdataPanel,每次发布时都会发生完全回发。唯一的区别是页面的唯一部分被发送回更新面板。基本上你减少了页面闪烁,而不是服务器开销。而且你有很多自动交易。
我的建议。删除更新面板,让Formviews和Gridviews尽可能少回发,然后将它们包装在更新面板中。丢失TextBoxen上的所有autopostback。唯一应该触发回发的东西是你的保存按钮。即使验证也应尽可能在客户端进行。