【发布时间】:2010-06-11 15:05:12
【问题描述】:
我正在使用 ajax 和 jquery 将内容加载到 div 中。
我的 jquery 是这样的
$("a.trigger").click(function() {
$.ajax({
type: "POST",
url: "GetStuff.aspx",
data: "id=0",
success: function(response){
$("#contentDiv").html(response);
}
});
});
在 GetStuff.aspx 中我想写一些 asp.net html 控件,比如
private void Page_Load(object sender, System.EventArgs e)
{
Response.Expires = -1;
Response.ContentType = "text/plain";
Response.Write("<asp:Label id=\"label1\" runat=\"server\" text=\"helloworld\"/>");
Response.End();
}
但是标签没有出现在页面上。
我试图将 asp:Label 像这样放在我的 aspx 文件中
<%@ Page Language="C#" Inherits="Untitled.GetStuff" %>
<asp:Label id="label12" runat="server" text="helloworld2"/>
它也不起作用。 如何让 asp.net html 控件显示出来?
【问题讨论】:
-
上面第二个例子的结果是什么?例如,是否有服务器错误?什么标记被发送到浏览器?在我看来,它应该已经完成了我认为您要问的事情(尽管它可能会创建一个无效的 DOM 状态,该状态会在 div 标签内包含 html 和 body 标签)。
-
好的,我重试了第二个示例,它完全符合我最初的要求。我不知道为什么我第一次尝试时得到了不同的结果。