aspnet multiview jquery ajax

时间:2013-09-26 17:42:04

标签: jquery asp.net ajax multiview

我带来了一个非常奇怪的情况。

我有一个带有AspNet多视图控件的表单。 我想每隔N秒保存一次内容。所以我每N秒发送一次ajax Post请求。

问题出现在回发号码10之后。在Post编号8之后,视图状态似乎已损坏,并且非可见视图中的所有控件都会丢失它们的值。

我的aspx页面:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="multiview-ajax-bug-    test.aspx.cs"
Inherits="multiview_ajax_bug_test"  Theme=""%>

<!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>
<script src="JS/jquery-1.10.2.min.js" type="text/javascript"></script>
<script type="text/javascript" src='<%= ResolveUrl("~/JS/auto-save.js") %>'></script>
</head>

<body>

<form id="form1" runat="server">
<div>
    <div id="subnavigation">
        <ul>
            <li>
                <asp:LinkButton ID="lnk_one" runat="server" Text="Page1" Font-Bold="true" OnClick="lnk_one_Click"></asp:LinkButton></li>
            <li>
                <asp:LinkButton ID="lnk_two" runat="server" Text="Page2" OnClick="lnk_two_Click"></asp:LinkButton></li>
            <li>
                <asp:LinkButton ID="lnk_three" runat="server" Text="Page3" OnClick="lnk_three_Click"></asp:LinkButton></li>
            <li>
                <asp:LinkButton ID="lnk_four" runat="server" Text="Page4" OnClick="lnk_four_Click"></asp:LinkButton></li>
        </ul>
        <asp:MultiView ID="ProjectMultiView" runat="server" ActiveViewIndex="0">
            <asp:View ID="vw_one" runat="server">
                one
                <asp:TextBox runat="server" ID="one"></asp:TextBox>
            </asp:View>
            <asp:View ID="vw_two" runat="server">
                two
                <asp:TextBox runat="server" ID="two"></asp:TextBox>
            </asp:View>
            <asp:View ID="vw_three" runat="server">
                three
                <asp:TextBox runat="server" ID="three"></asp:TextBox>
            </asp:View>
            <asp:View ID="vw_four" runat="server">
                four
                <asp:TextBox runat="server" ID="four">
                </asp:TextBox>
            </asp:View>
        </asp:MultiView>
        <div class="clearboth">
        </div>
    </div>
</div>
<script type="text/javascript">

    // save every two minutes
    $(function () {
        var formId = '<%= Form.ClientID  %>';
        var url = location.href;

        var interval = 1 * 1 * 1000; // 1 secs
        setInterval(saveDraft, interval);

        function saveDraft() {
            autoSave(formId, url);
        }

    });
</script>
</form>
</body>
</html>

我的自动保存功能:

// auto-save.js
// Posts an ajax request to the server, the server side needs to check that it is an ajax request and save the content
// Requires JQuery 1.10 at least

function autoSave(formId, url, statusControlId) {
$.ajax({
    url: url,
    cache: false,
    method: "POST",
    data: $("#" + formId).serialize(),
    success: function (data) {
        if (statusControlId) {
            $("#" + statusControlId).html("");
            $("#" + statusControlId).html("success");
        }
    },
    error: function () {
        if (statusControlId) {
            $("#" + statusControlId).html("");
            $("#" + statusControlId).html("error");
        }
    }
});
}

代码背后:

using System;


public partial class multiview_ajax_bug_test : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    protected void lnk_one_Click(object sender, EventArgs e)
    {
        ProjectMultiView.SetActiveView(vw_one);
    }

    protected void lnk_two_Click(object sender, EventArgs e)
    {
        ProjectMultiView.SetActiveView(vw_two);
    }

    protected void lnk_three_Click(object sender, EventArgs e)
    {
       ProjectMultiView.SetActiveView(vw_three);
    }

    protected void lnk_four_Click(object sender, EventArgs e)
    {
        ProjectMultiView.SetActiveView(vw_four);
    }
}

是否有任何明显的遗漏,或者它是Multiview控件的错误?

0 个答案:

没有答案