巴顿在更新面板是做一个完整的回发? [英] Button in update panel is doing a full postback?

查看:155
本文介绍了巴顿在更新面板是做一个完整的回发?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我下面如何使用更新面板从这里(http://www.asp.net/Ajax/Documentation/Live/tutorials/IntroductionUpdatePanel.aspx)一个简单的例子。更新面板之外,我的另一个HTML输入控制,调用JavaScript函数,在警告框中显示的数给用户。简单的东西。我的问题是,IIS和内置的asp.net web服务器(卡西尼)上运行时的页面表现不同。在IIS单击按钮内更新面板导致完全回发,因此显示在JS功能的用户的计数eachtime之后被重置。根据内置的Web服务器命中更新面板内的按钮的行为我怎么会想到它,我希望它,因为它只是刷新,这样在客户端的计数器不复位的标签。

.NET 3.5的目标框架,我运行IIS 5.1。

我见过其他地方的职位描述了同样的问题(http://forums.asp.net/t/1169282.aspx)

 < HTML的xmlns =htt​​p://www.w3.org/1999/xhtml>
<头=服务器>
    <冠军>无标题页< /标题>

    <脚本类型=文/ JavaScript的>
    变种数= 0;
    功能incrementCounter()
    {
        算上++;
        警报(计数);
    }
    < / SCRIPT>
< /头>
<身体GT;
    <表格ID =Form1的=服务器>
    < ASP:ScriptManager的ID =ScriptManager1=服务器>
    < / ASP:ScriptManager的>
    < ASP:UpdatePanel的ID =UpdatePanel1=服务器>
        <的ContentTemplate>
            < ASP:标签ID =标签1=服务器文本=面板中创建>< / ASP:标签>
            < ASP:按钮的ID =Button1的=服务器文本=按钮的onclick =的button1_Click/>
        < /的ContentTemplate>
    < / ASP:UpdatePanel的>

    <输入类型=按钮ID =Button2的值=JS唱首歌的onclick =incrementCounter(); />
    < /形式GT;
< /身体GT;
< / HTML>
 

更新:

感谢Crossbrowser你的答案。我的回答会占用到很大的空间,在添加注释窗口。好了,下面这个简单的例子在这里(http://www.asp.net/Ajax/Documentation/Live/tutorials/IntroductionUpdatePanel.aspx),你可以看到更新模式未设置为条件,所以我已经反映了这些变化。但我的问题仍然存在。这是在IIS上运行时,页面会导致完全回发。即您浏览器加载进度条,屏幕闪烁,客户端计数,我是保持丢失。在内置asp.net web服务器运行code没有。这是我的问题的症结所在。我遇到了这个问题,其他人(http://forums.asp.net/t/1169282.aspx)。

所以我的问题是运行在IIS上比内置asp.net之一,当有什么不同?

更新code:

 < HTML的xmlns =htt​​p://www.w3.org/1999/xhtml>
<头=服务器>
    <冠军>无标题页< /标题>

    <脚本类型=文/ JavaScript的>
    变种数= 0;
    功能incrementCounter()
    {
        算上++;
        警报(计数);
    }
    < / SCRIPT>
< /头>
<身体GT;
    <表格ID =Form1的=服务器>
    < ASP:ScriptManager的ID =ScriptManager1=服务器>
    < / ASP:ScriptManager的>
    < ASP:UpdatePanel的ID =UpdatePanel1=服务器>
        <的ContentTemplate>
            < ASP:标签ID =标签1=服务器文本=面板中创建>< / ASP:标签>
            < ASP:按钮的ID =Button1的=服务器文本=按钮的onclick =的button1_Click/>
        < /的ContentTemplate>
    < / ASP:UpdatePanel的>

    <输入类型=按钮ID =Button2的值=JS唱首歌的onclick =incrementCounter(); />
    < /形式GT;


< /身体GT;
< / HTML>
 

由于您使用的是.NET Framework 3.5的解决方案

我会假设你正在使用Visual Studio 2008,你说你是针对IIS 5.1的生产平台。

本地Web服务器是Visual Studio 2008中的一部分是基于关闭IIS 6/7的建筑,而不是IIS 5。因此,要回答你的相比,本地Web服务器什么是与IIS不同的问题...不幸的是在这种情况下,你混合苹果和桔子。

您仅限于IIS 5.1?...即客户授权或某些其他原因。如果你不是,你正在开发使用Visual Studio 2008(.NET Framework 3.5的),你真的应该使用IIS7的(或至少6位),你很可能不会有这个问题。

再次IIS7可能不适合你的选择。

I'm following a simple example of how to use the update panel from here (http://www.asp.net/Ajax/Documentation/Live/tutorials/IntroductionUpdatePanel.aspx). Outside the update panel i've another html input control which calls a javascript function which displays an count to the user in an alert box. simple stuff. My problem is that the page behaves differently when running on IIS and on the inbuilt asp.net web server (cassini). Under IIS clicking the button within the update panel causes a full postback and so the count displayed to the user in the js function gets reset after that eachtime. under the inbuilt web server hitting the button inside the update panel behaves how i would expect it to and how i want it to in that it refreshes the label only so that the counter on the client side isn't reset.

.net 3.5 is the target framework and I'm running IIS 5.1.

I've seen posts elsewhere describing the same problem (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:

Thanks Crossbrowser for your answer. My reply will take up to much room in the Add Comment window. Ok, so following this simple example here (http://www.asp.net/Ajax/Documentation/Live/tutorials/IntroductionUpdatePanel.aspx) you can see that the update mode is not set to conditional so I've reflected those changes. However my problem still persists. That is that the page when running on IIS causes a full postback. i.e. the progress bar in you browser loads, the screen flickers, client side count that i was maintaining is lost. Running the code on the inbuilt asp.net webserver does not. That is the crux of my problem. I've come across this problem by others (http://forums.asp.net/t/1169282.aspx).

So my question is what is different when running on IIS compared to the inbuilt asp.net one?

Updated Code:

<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>

解决方案

Since you are using the .NET Framework 3.5 I will assume you are using Visual Studio 2008, and you say you are targeting IIS 5.1 for the production platform.

The local web server that is part of Visual Studio 2008 is based off of IIS 6/7 architecture, not IIS 5. So, to answer your question of what is different with IIS compared to the local web server... unfortunately, in this case, you are mixing apples and oranges.

Are you restricted to IIS 5.1?... ie client mandate or some other reason. If you are not, and you are developing with Visual Studio 2008 (.NET Framework 3.5) you really should be using IIS7 (or at least 6) as you would most likely not have this problem.

Again, IIS7 may not be an option for you.

这篇关于巴顿在更新面板是做一个完整的回发?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆