當我通過F5或View In Browser運行應用程序時遇到一個奇怪的問題。當我第一次運行以下頁面時,文本框中顯示「Hello」。點擊「點擊我」按鈕,文字將變爲「點擊!」。沒關係。關閉瀏覽器並再次運行F5(或在瀏覽器中查看),文本框顯示「Clicked!」。它不再顯示初始值。我在IE6上看到這個問題(這是我僱主的唯一選擇),但不是FF3.6,也不是谷歌Chrome 4.x。我認爲這可能與ViewState有關。但是,ViewState被禁用後,問題仍然存在。Asp.Net控制第一次運行後初始值不顯示
任何想法或提示出了什麼問題?
下面Default.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" enableviewstate="false">
<div>
<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Click Me" EnableViewState="false" UseSubmitBehavior="true" />
<asp:TextBox ID="TextBox1" runat="server" Text="Hello" EnableViewState="false" ></asp:TextBox>
</div>
</form>
</body>
</html>
Default.aspx.cs以下文件:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
TextBox1.Text = "Clicked!";
}
}