[英]aspx page with update panel not work after load in master page with jQuery ajax
I Have a aspx page contain update panel . 我有一个aspx页面包含更新面板。 and load that page by using jquery ajax inside div in master page .However, the content off update panel just update for first time and other time not update. 并在母版页的div中使用jquery ajax加载该页面。但是,更新面板之外的内容只是第一次更新,而其他时间则不更新。
My Master Page: 我的母版页:
<head id="Head1" runat="server">
<script src="Script/jquery-1.10.2.min.js" type="text/javascript"></script>
<script src="Script/site.js" type="text/javascript"></script>
<asp:ContentPlaceHolder ID="head" runat="server">
</asp:ContentPlaceHolder>
</head>
<body>
<form id="form1" runat="server">
<div id="content">
<div class="main">
<asp:ContentPlaceHolder ID="contentMain" runat="server">
</asp:ContentPlaceHolder>
</div>
</div>
</form>
</body>
My ASPX Page 我的ASPX页面
<head runat="server">
</head>
<body>
<form id="form2" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel runat="server" ID="UpdatePanel" UpdateMode="Conditional">
<ContentTemplate>
<div style="text-align:center; margin:50px">
<asp:Button ID="btnUpdate" runat="server" Text="update" Width="50px"
onclick="btnUpdate_Click"/>
<br />
<asp:Label ID="lblTime" runat="server"></asp:Label>
</div>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="btnReg" EventName="Click" />
</Triggers>
</asp:UpdatePanel>
</form>
</body>
</html>
My ASPX Page Code Behind 我的ASPX页面代码背后
protected void btnUpdate_Click(object sender, EventArgs e)
{
lblTime.Text = DateTime.Now.ToString();
}
My JavaScript 我的JavaScript
$(document).ready(function () {
$(window).load(function () {
loadContent();
});
});
function loadContent() {
$.ajax({
type: 'get',
url: 'Page.aspx',
contentType: 'application/html; charset=utf-8',
dataType: 'html',
beforeSend: sendContent,
success: successContent,
error: errorContent
});
}
function sendContent() {
////loading
}
function successContent(data, status) {
$("#content .main").html(data);
$("#content").show();
}
function errorContent(request, status, error) {
////error
}
thanks a lot 非常感谢
In the code you provided you never call function loadContent. 在您提供的代码中,您永远不会调用loadContent函数。 I added the loadContent to jQuery ready() and it work on my computer. 我将loadContent添加到jQuery ready()中,并且可以在我的计算机上使用。
If you have two forms on your page you have two "StateView" variables. 如果页面上有两种形式,则有两个“ StateView”变量。 When asp.net checks for the variable it throws error probably because the state variable comes the second time from the form of Site.Manager and not from Page.aspx. 当asp.net检查变量时,它将引发错误,可能是因为状态变量第二次来自Site.Manager而不是Page.aspx。 I just deleted the form on Master Page and now the button works perfectly. 我刚刚删除了母版页上的表单,现在该按钮可以正常使用了。
My Master Page: 我的母版页:
<%@ Master Language="C#" CodeBehind="Site.master.cs" Inherits="WebApplication4.SiteMaster" %>
<!DOCTYPE html>
<html lang="en">
<head id="Head1">
<script src="Scripts/jquery-1.10.2.min.js" type="text/javascript"></script>
<script src="Scripts/site.js" type="text/javascript"></script>
</head>
<body>
<div id="content">
<div class="main">
</div>
</div>
</body>
</html>
My Page.aspx 我的Page.aspx
<%@ Page Language="C#" CodeBehind="Page.aspx.cs" Inherits="WebApplication4.Page" %>
<form id="form2" enableviewstate="false" runat="server">
<asp:ScriptManager ID="ScriptManager1">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel" UpdateMode="Conditional">
<ContentTemplate>
<asp:Button ID="btnUpdate" Text="update" Width="50px"
onclick="btnUpdate_Click" runat="server"/>
<asp:Label ID="lblTime" runat="server"></asp:Label>
//////////// Some Tags ///////////
</ContentTemplate>
</asp:UpdatePanel>
</form>
My ASPX Page Code Behind 我的ASPX页面代码背后
protected void btnUpdate_Click(object sender, EventArgs e)
{
lblTime.Text = DateTime.Now.ToString();
}
site.js site.js
function loadContent() {
$.ajax({
type: 'get',
url: 'Page.aspx',
contentType: 'application/html; charset=utf-8',
dataType: 'html',
beforeSend: sendContent,
success: successContent,
error: errorContent
});
}
function sendContent() {
////loading
}
function successContent(data, status) {
$("#content .main").html(data);
$("#content").show();
}
function errorContent(request, status, error) {
////error
}
$(function () {
loadContent();
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.