Asp.net ASP FormView和DetailsView在回发后返回默认值

Asp.net ASP FormView和DetailsView在回发后返回默认值,asp.net,postback,detailsview,formview,Asp.net,Postback,Detailsview,Formview,在我的aspx文件中,我有两个标签,一个FormView和一个DetailsView。 在预渲染期间,我手动设置标签的文本(我的应用程序支持多种语言,标签是根据userprofile设置的)。此外,FormView和DetaiView中的标签文本也在预渲染期间设置。我使用.FindControl方法获取对实际控件的引用。 最后,也是在预渲染期间,我创建了各种验证程序控件,并手动将它们添加到FormView和DetailsView中 当我的网页第一次加载以上所有作品刚刚好 当我引起回发时,按下Fo

在我的aspx文件中,我有两个标签,一个FormView和一个DetailsView。 在预渲染期间,我手动设置标签的文本(我的应用程序支持多种语言,标签是根据userprofile设置的)。此外,FormView和DetaiView中的标签文本也在预渲染期间设置。我使用.FindControl方法获取对实际控件的引用。 最后,也是在预渲染期间,我创建了各种验证程序控件,并手动将它们添加到FormView和DetailsView中

当我的网页第一次加载以上所有作品刚刚好

当我引起回发时,按下FormView或DetailsView内的按钮或更改下拉框的选择,页面预渲染被触发;正在设置文本,并创建和添加验证程序

现在它来了;回发后,一旦页面在浏览器中刷新,标签就会显示其默认文本(如在aspx文件中设置的),我的验证程序控件也就消失了

有没有人也经历过这种情况,是什么导致了这种行为?更重要的是,我如何解决这个问题

编辑-添加要复制的示例代码

我刚刚制作了一个非常干净的示例项目来重现这种行为。 以下是aspx:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" 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:FormView ID="fvwCalculateHeartRateZones" runat="server" DataSourceID="odsHeartRateZones" DefaultMode="Insert">
            <InsertItemTemplate>

                <asp:Label ID="lblHFMax" runat="server" SkinID="LabelHeader4" Text="_Max"></asp:Label>

                <asp:TextBox ID="txtHFMax" runat="server" SkinID="TextBoxDefault" Text='<%# Bind("iHFMax") %>' Width="80px"></asp:TextBox>

                <asp:Button ID="btnHFZCalculate" runat="server" CommandName="Insert" SkinID="ButtonDefault" Text="_Calculate" ValidationGroup="HFZCalculate" Width="100" />

            </InsertItemTemplate>
        </asp:FormView>


        <asp:ObjectDataSource ID="odsHeartRateZones" runat="server" 
            TypeName="HeartRateZones"
            DataObjectTypeName="HeartRateZones"
            InsertMethod="InsertByCalculation" >
        </asp:ObjectDataSource>

    </div>
    </form>
</body>
</html>
最后是ObjectDataSource使用的类

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

public class HeartRateZones
{
    public int iHFMax { get; set; }

    public HeartRateZones()
    {
        //
        // Add constructor logic here
        //
    }

    public static int InsertByCalculation(HeartRateZones oAEntry)
    {
        return 0;
    }
}
所有这些都非常基本和简单。当您运行页面时,您将看到标签的标题和按钮设置为“MaxP”和“Calculate”


在按下“计算”按钮之前,请确保插入一个数字值(例如0)。然后按下计算按钮。您将看到标签和按钮的标题返回到其默认值“\u Max”和“\u Calculate”

您应该只在页面未回发时进行初始绑定您应该只在页面未回发时进行初始绑定
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

public class HeartRateZones
{
    public int iHFMax { get; set; }

    public HeartRateZones()
    {
        //
        // Add constructor logic here
        //
    }

    public static int InsertByCalculation(HeartRateZones oAEntry)
    {
        return 0;
    }
}