通过这段在页面中插入ascx。
$.ajax({
type: "POST", //POST
url: "GridViewDrillDownjQueryAjax.aspx/GetOrders", //Set call to Page Method
data: params, // Set Method Params
beforeSend: function(xhr) {
xhr.setRequestHeader("Content-type", "application/json; charset=utf-8");},
contentType: "application/json; charset=utf-8", //Set Content-Type
dataType: "json", // Set return Data Type
success: function(msg, status) {
$('#progress').css('visibility','hidden');
$(master).children()[0].src = src;
$(detail).html(msg);
$(detail).slideToggle("normal"); // Succes Callback
},
error: function(xhr,msg,e){
alert(msg);//Error Callback
}
});然后ascx的源码是
<asp:SqlDataSource ID="sqlDsOrders" runat="server" ConnectionString="<%$ ConnectionStrings:Northwind %>"
SelectCommand="SELECT [OrderID], [OrderDate], [RequiredDate], [Freight], [ShippedDate] FROM [Orders] WHERE ([CustomerID] = @CustomerID)">
<SelectParameters>
<asp:Parameter Name="CustomerID" Type="String" DefaultValue="" />
</SelectParameters>
</asp:SqlDataSource>
<asp:Repeater ID="List" DataSourceID="sqlDsOrders" runat="server">
<HeaderTemplate>
<table class="grid" cellspacing="0" rules="all" border="1" style="border-collapse: collapse;">
<tr>
<th scope="col"> </th>
<th scope="col">Order ID</th>
<th scope="col">Date Ordered</th>
<th scope="col">Date Required</th>
<th scope="col" style="text-align: right;">Freight</th>
<th scope="col">Date Shipped</th>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr class='<%# (Container.ItemIndex%2==0) ? "row" : "altrow" %>'>
<td class="rownum"><%# Container.ItemIndex+1 %></td>
<td style="width: 80px;"><%# Eval("OrderID") %></td>
<td style="width: 100px;"><%# Eval("OrderDate","{0:dd/MM/yyyy}") %></td>
<td style="width: 110px;"><%# Eval("RequiredDate", "{0:dd/MM/yyyy}")%></td>
<td style="width: 50px; text-align: right;"><%# Eval("Freight","{0:F2}") %></td>
<td style="width: 100px;"><%# Eval("ShippedDate", "{0:dd/MM/yyyy}")%></td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>gerorders函数如下
public static string GetOrders(string customerId)
{
System.Threading.Thread.Sleep(500);
Page page = new Page();
CustomerOrders ctl = (CustomerOrders)page.LoadControl("CustomerOrders.ascx");
ctl.CustomerId = customerId;
page.Controls.Add(ctl);
System.IO.StringWriter writer = new System.IO.StringWriter();
HttpContext.Current.Server.Execute(page, writer, false);
string output = writer.ToString();
writer.Close();
return output;
}
我想在ascx中加入textbox控件和button。但一加入,ajax这段就会运行弹出出错提示的窗口。为什么。
$.ajax({
type: "POST", //POST
url: "GridViewDrillDownjQueryAjax.aspx/GetOrders", //Set call to Page Method
data: params, // Set Method Params
beforeSend: function(xhr) {
xhr.setRequestHeader("Content-type", "application/json; charset=utf-8");},
contentType: "application/json; charset=utf-8", //Set Content-Type
dataType: "json", // Set return Data Type
success: function(msg, status) {
$('#progress').css('visibility','hidden');
$(master).children()[0].src = src;
$(detail).html(msg);
$(detail).slideToggle("normal"); // Succes Callback
},
error: function(xhr,msg,e){
alert(msg);//Error Callback
}
});然后ascx的源码是
<asp:SqlDataSource ID="sqlDsOrders" runat="server" ConnectionString="<%$ ConnectionStrings:Northwind %>"
SelectCommand="SELECT [OrderID], [OrderDate], [RequiredDate], [Freight], [ShippedDate] FROM [Orders] WHERE ([CustomerID] = @CustomerID)">
<SelectParameters>
<asp:Parameter Name="CustomerID" Type="String" DefaultValue="" />
</SelectParameters>
</asp:SqlDataSource>
<asp:Repeater ID="List" DataSourceID="sqlDsOrders" runat="server">
<HeaderTemplate>
<table class="grid" cellspacing="0" rules="all" border="1" style="border-collapse: collapse;">
<tr>
<th scope="col"> </th>
<th scope="col">Order ID</th>
<th scope="col">Date Ordered</th>
<th scope="col">Date Required</th>
<th scope="col" style="text-align: right;">Freight</th>
<th scope="col">Date Shipped</th>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr class='<%# (Container.ItemIndex%2==0) ? "row" : "altrow" %>'>
<td class="rownum"><%# Container.ItemIndex+1 %></td>
<td style="width: 80px;"><%# Eval("OrderID") %></td>
<td style="width: 100px;"><%# Eval("OrderDate","{0:dd/MM/yyyy}") %></td>
<td style="width: 110px;"><%# Eval("RequiredDate", "{0:dd/MM/yyyy}")%></td>
<td style="width: 50px; text-align: right;"><%# Eval("Freight","{0:F2}") %></td>
<td style="width: 100px;"><%# Eval("ShippedDate", "{0:dd/MM/yyyy}")%></td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>gerorders函数如下
public static string GetOrders(string customerId)
{
System.Threading.Thread.Sleep(500);
Page page = new Page();
CustomerOrders ctl = (CustomerOrders)page.LoadControl("CustomerOrders.ascx");
ctl.CustomerId = customerId;
page.Controls.Add(ctl);
System.IO.StringWriter writer = new System.IO.StringWriter();
HttpContext.Current.Server.Execute(page, writer, false);
string output = writer.ToString();
writer.Close();
return output;
}
我想在ascx中加入textbox控件和button。但一加入,ajax这段就会运行弹出出错提示的窗口。为什么。
我不加入textbox前可以成功运行的。加入之后就出错了