我正在遵循一个如何使用此处的更新面板的简单示例(http://www.asp.net/Ajax/Documentation/Live/tutorials/IntroductionUpdatePanel.aspx)。在更新面板之外,我有另一个 html 输入控件,它调用一个 javascript 函数,该函数在警报框中向用户显示计数。简单的东西。我的问题是,在 IIS 和内置的 asp.net Web 服务器(cassini)上运行时,页面的行为不同。在 IIS 下,单击更新面板中的按钮会导致完全回发,因此每次在 js 函数中向用户显示的计数都会重置。在内置的网络服务器下,点击更新面板内的按钮会按照我期望的方式运行,因为它只会刷新标签,这样客户端的计数器就不会重置。
.net 3.5 是目标框架,我正在运行 IIS 5.1。
我在其他地方看到过描述同样问题的帖子(http://forums.asp.net/t/1169282.aspx)
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
<script type="text/javascript">
var count=0;
function incrementCounter()
{
count ++;
alert(count);
}
</script>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:Label ID="Label1" runat="server" Text="Panel Created"></asp:Label>
<asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" />
</ContentTemplate>
</asp:UpdatePanel>
<input type="button" id="Button2" value="JS Clicker" onclick="incrementCounter();" />
</form>
</body>
</html>
Update:
感谢 Crossbrowser 的回答。我的回复将占用“添加评论”窗口中的大量空间。好的,下面这个简单的例子(http://www.asp.net/Ajax/Documentation/Live/tutorials/IntroductionUpdatePanel.aspx)您可以看到更新模式未设置为有条件,因此我已反映了这些更改。然而我的问题仍然存在。也就是说,该页面在 IIS 上运行时会导致完全回发。即浏览器中的进度条加载,屏幕闪烁,我维护的客户端计数丢失。在内置的 asp.net Web 服务器上运行代码不会。这就是我的问题的症结所在。我在其他人那里也遇到过这个问题(http://forums.asp.net/t/1169282.aspx).
所以我的问题是,与内置的 asp.net 相比,在 IIS 上运行时有什么不同?
更新的代码:
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
<script type="text/javascript">
var count=0;
function incrementCounter()
{
count ++;
alert(count);
}
</script>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:Label ID="Label1" runat="server" Text="Panel Created"></asp:Label>
<asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" />
</ContentTemplate>
</asp:UpdatePanel>
<input type="button" id="Button2" value="JS Clicker" onclick="incrementCounter();" />
</form>
</body>
</html>
由于您使用的是 .NET Framework 3.5,我假设您使用的是 Visual Studio 2008,并且您说您的生产平台目标是 IIS 5.1。
作为 Visual Studio 2008 一部分的本地 Web 服务器基于 IIS 6/7 体系结构,而不是 IIS 5。因此,要回答您的问题:与本地 Web 服务器相比,IIS 有何不同...不幸的是,在此例子,你正在混合苹果和橙子。
您是否仅限于 IIS 5.1?...即客户端授权或其他原因。如果不是,并且您正在使用 Visual Studio 2008 (.NET Framework 3.5) 进行开发,那么您确实应该使用 IIS7(或至少 6),因为您很可能不会遇到此问题。
同样,IIS7 可能不适合您。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)