【发布时间】:2016-11-14 20:26:33
【问题描述】:
我正在尝试将 aspx 文件加载到 div 中,但如果 aspx 文件具有 asp.net 控件,它将无法工作。 (这有点意思。)如果我只有 html 控件,它可以正常工作,但不适用于 runat="server"。我已经剥离了主文件和 .aspx 文件,几乎一无所有。此外,后面的代码没有捕获传入的数据 - PageSize。即使只使用 html 元素也不行。为什么aspx页面加载不出来?我试过取出所有的 html 标签,将数据作为 "PageSize":"50"、"PageSize":50 和其他组合传递。没有运气。
<%@ Language="C#" AutoEventWireup="true" CodeBehind="Site.master.cs" Inherits="jQueryTutorial.SiteMaster" %>
<!DOCTYPE html>
<html lang="en">
<head runat="server">
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title></title>
<webopt:BundleReference runat="server" Path="~/Content/css" />
<script src="Scripts/jquery-1.10.2.js"></script>
<script type="text/javascript">
$(document).ready(function () {
$('#MyButton').click(function () {
$('#OutputDiv').load('GetCustomers.aspx', { PageSize: 10 },
function (response, status, xhr)
{
if (status == "error")
alert(xhr.error);
//else
// alert('Loaded');
});
});
});
</script>
</head>
<body>
<button id="MyButton">Click to get HTML</button>
<div id="OutputDiv"></div>
</body>
</html>
要加载的.aspx文件:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="GetCustomers.aspx.cs" Inherits="jQueryTutorial.GetCustomers" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
</head>
<body>
<input type="button" value="Press me" />
<input id="abc" />
<%-- <asp:Button ID="Button1" Text="Button" runat="server" />--%>
</body>
</html>
要加载的asps文件后面的代码:
using System;
namespace jQueryTutorial
{
public partial class GetCustomers : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
var pageSize = 50;
if (Request["PageSize"] != null)
pageSize = Int32.Parse(Request["PageSize"]);
}
}
}
【问题讨论】:
-
那么,你得到的具体错误是什么?
-
更新:我发现了部分问题。我正在关注 Pluralsight - jQuery Fundamentals 中的一个示例。该示例使用 html 页面作为父页面。我使用的是默认的 Web 表单应用程序,因此 site.master 文件有一个表单标签。我在点击事件中添加了“return false”,以便返回所有记录,但我仍然没有得到通过“{ PageSize:50}的数据。当我打破GetCustomers.aspx的表单加载事件时,Request [“PageSize "] 始终为空。
-
另一个更新:仍然无法使用 .load 传递页面大小变量,但 .get 有效。