我创建了一个AJAX.NET应用程序,并在<add tagPrefix="asp" namespace="System.Web.UI" assembly="System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />的帮助下运行我的应用程序,但现在我的以下示例代码将在每次单击按钮时回发。我需要在不重新加载页面的情况下完成该操作。
代码如下。
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="test.aspx.cs" Async="true" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="Button1" EventName="Click" />
</Triggers>
<ContentTemplate>
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
<asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" />
</ContentTemplate>
</asp:UpdatePanel>
</div>
</form>
</body>
</html>
using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
Label1.Text = "Hello";
}
}发布于 2011-10-17 02:25:01
我用下面的方法找到了解决方案
发布于 2011-10-12 22:08:38
当您遇到此类问题时,最好使用相同版本的.Net创建一个新项目,并查看它在您的web.config中放置了什么内容。
对于.Net 3.5,它创建以下内容:
<add tagPrefix="asp" namespace="System.Web.UI" assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add tagPrefix="asp" namespace="System.Web.UI.WebControls" assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>发布于 2011-10-14 00:27:20
我采用了您的示例,并通过以下步骤使其正常工作:
检查您的计算机上是否安装了正确的程序集。在您的例子中,您将需要ASP.NET AJAX1.0,可以从以下地址下载:http://www.microsoft.com/download/en/details.aspx?displaylang=en&id=883
这将在您的GAC中安装System.Web.Extensions 1.0.61025.0程序集。
在您的网站中引用该程序集。
检查您的web.config是否至少具有以下配置:
<system.web>
<compilation debug="true">
<assemblies>
<add assembly="System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
</assemblies>
</compilation>
<pages>
<controls>
<add tagPrefix="asp" namespace="System.Web.UI" assembly="System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
</controls>
</pages>
<httpHandlers>
<remove verb="*" path="*.asmx"/>
<add verb="*" path="*.asmx" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
<add verb="GET" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler" validate="false"/>
</httpHandlers>
other stuff
</system.web>我的页面后面的代码是:
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void button1_click(object sender, EventArgs e)
{
Label1.Text = "Hello";
}
}我的页面的设计器文件是:
public partial class WebForm1 {
protected global::System.Web.UI.HtmlControls.HtmlForm form1;
protected global::System.Web.UI.ScriptManager ScriptManager1;
protected global::System.Web.UI.UpdatePanel UpdatePanel1;
protected global::System.Web.UI.WebControls.Label Label1;
protected global::System.Web.UI.WebControls.Button Button1;
}就这样。正如Yuriy Rozhovetskiy所说:如果你点击按钮,page_load的执行是正常的行为!
https://stackoverflow.com/questions/7718171
复制相似问题