同样的Ajax调用在.net项目中表现不同

时间:2017-03-13 16:15:24

标签: c# jquery asp.net ajax .net-4.0

我有一个带有ajax调用的简单webform,它执行完美,但是当我将相同的代码放入现有项目时,ajax调用会刷新页面。该项目是.net 2.0转换为.net 4.0。这是简单的代码:

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
        <asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
<asp:Timer ID="Timer1" runat="server" Interval="5000" ontick="Timer1_Tick"></asp:Timer> 



    <asp:TextBox ID="TextBox1" runat="server" 
    Height="118px" TextMode="MultiLine" Width="468px"></asp:TextBox>
    <asp:Button ID="Button1" runat="server" Text="Save" 
    onclick="Button1_Click" /><br /><br />

<asp:UpdatePanel ID="UpdatePanel1" runat="server">

    <ContentTemplate>
        <asp:TextBox ID="TextBox2" runat="server" Height="120px" 
        TextMode="MultiLine" Width="466px"></asp:TextBox>
    </ContentTemplate>

    <Triggers>
        <asp:AsyncPostBackTrigger ControlID="Timer1" EventName="Tick"/>
    </Triggers>

</asp:UpdatePanel> 


    <div>

    </div>
    </form>
</body>
</html>

cs代码:         protected void Button1_Click(object sender,EventArgs e)         {             保存();         }

    private void Save()
    {
        //Add the save function here ex store the text to DB
        //Here we only move between the two textboxes to show that it works
        TextBox2.Text = TextBox1.Text;
    }
    protected void Timer1_Tick(object sender, EventArgs e)
    {
        Save();
    }

1 个答案:

答案 0 :(得分:0)

更新。我找到了这个问题,这一行: xhtmlConformance mode =“Legacy”
在从.net 2.0转换过程中添加到webconfig。

评论此行可修复ajax刷新。