在Ajax中當你要使用updatepanel控制項時,首先要先拖一個scriptmanager控制項。
在updatepanel中updatemode與ChildrenAsTriggers怎樣組合才不衝突呢?
UpdateMode =Always ChildrenAsTriggers =false(此種組合衝突)
UpdateMode =Always ChildrenAsTriggers =true (此種有效)
UpdateMode =Conditional ChildrenAsTriggers =true (此種有效)
UpdateMode =Conditional ChildrenAsTriggers =false(此種有效)
不同的組合方式,不同的位置,顯示出不同情況的重新整理與跳轉,如下一段代碼(此處只顯示一種組合一種位置的情況):
<form id="form1" runat="server">
<div id='time'><%=System .DateTime .Now.ToString () %>
<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
</div>
<asp:UpdatePanel ID="UpdatePanel1" runat="server" RenderMode =Block UpdateMode =Always ChildrenAsTriggers =true >
<ContentTemplate>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="Data Source=.;Initial Catalog=B2B;User ID=sa;Password=sa"
ProviderName="System.Data.SqlClient"
SelectCommand="SELECT [ProductId], [ProductName], [ProductType], [ProductPrice], [ProductQuantity], [ProductAddress] FROM [Products]">
</asp:SqlDataSource>
<asp:GridView ID="GridView1" runat="server" AllowPaging="True"
AutoGenerateColumns="False" DataKeyNames="ProductId"
DataSourceID="SqlDataSource1" PageSize="15" EnableViewState="False">
<Columns>
<asp:BoundField DataField="ProductId" HeaderText="ProductId"
InsertVisible="False" ReadOnly="True" SortExpression="ProductId" />
<asp:BoundField DataField="ProductName" HeaderText="ProductName"
SortExpression="ProductName" />
<asp:BoundField DataField="ProductType" HeaderText="ProductType"
SortExpression="ProductType" />
<asp:BoundField DataField="ProductPrice" HeaderText="ProductPrice"
SortExpression="ProductPrice" />
<asp:BoundField DataField="ProductQuantity" HeaderText="ProductQuantity"
SortExpression="ProductQuantity" />
<asp:BoundField DataField="ProductAddress" HeaderText="ProductAddress"
SortExpression="ProductAddress" />
</Columns>
</asp:GridView>
<asp:Button ID="Button1" runat="server" Text="Button"
onclick="Button1_Click" />
</ContentTemplate>
</asp:UpdatePanel>
<div id="demo"> </div>
</form>
當updatemode=Always 時,
當botton按鈕與GridView控制項同在一個updatepanel中時,id為time的div時間不重新整理,而gridview實現頁面的跳轉;
當botton按鈕與GridView控制項在兩個updatepanel中時,id為time的div時間不重新整理,而gridview實現頁面的跳轉;
當botton在id為demo的div中,gridview在updatepanel中時,id為time的div時間重新整理,gridview實現頁面的跳轉;
當updatemode=Conditional時,
當botton按鈕與GridView控制項同在一個updatepanel中時,id為time的div時間不重新整理,而gridview實現頁面的跳轉;
當botton按鈕與GridView控制項在兩個updatepanel中時,id為time的div時間不重新整理,gridview也不實現頁面的跳轉;
當botton在id為demo的div中,gridview在updatepanel中時,id為time的div時間重新整理,gridview實現頁面的跳轉;