【問題重現】
新建一個頁面,頁面中有三個Label,一個Button
在頁面第一次加載時,通過三種方法為上述三個Label加紅色底(BackColor)
上述Button事件中僅僅用來回傳頁面。
【問題】
在VS2003中,在點擊Button后,三個Label的底色都沒有丟失
在VS2005中,在點擊Button后,前兩個Label的底色沒有丟失,但第三個Label的底色卻丟失了!!
請高手指點,為什么會這樣?【我的操作】(1)在VS2003中新建一個頁面,前臺HTML文件如下:<%@ Page language="c#" Codebehind="Test3.aspx.cs" AutoEventWireup="false" Inherits="pm.Test3" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>Test3</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<asp:Label id="lblTest1" runat="server"> </asp:Label>
<asp:Label id="lblTest2" runat="server"> </asp:Label>
<asp:Label id="lblTest3" runat="server"> </asp:Label>
<asp:Button id="btnTest" runat="server" Text="回傳"></asp:Button>
</form>
</body>
</HTML>后臺CS代碼如下:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;namespace pm
{
public class Test3 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Label lblTest2;
protected System.Web.UI.WebControls.Label lblTest3;
protected System.Web.UI.WebControls.Button btnTest;
protected System.Web.UI.WebControls.Label lblTest1;
private void Page_Load(object sender, System.EventArgs e)
{
if(!this.Page.IsPostBack)
{
this.PadColor() ;
}
}
private void PadColor()
{
this.lblTest1.BackColor = System.Drawing.Color.Red; //OK this.lblTest2.BackColor = System.Drawing.Color.FromName("Red"); //OK //回傳后色彩并沒有丟失
this.lblTest3.BackColor = System.Drawing.Color.FromName("#FF0000");
} #region Web Form 設計工具產生的程式碼
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 此為 ASP.NET Web Form 設計工具所需的呼叫。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 此為設計工具支援所必須的方法 - 請勿使用程式碼編輯器修改
/// 這個方法的內容。
/// </summary>
private void InitializeComponent()
{
this.btnTest.Click += new System.EventHandler(this.btnTest_Click);
this.Load += new System.EventHandler(this.Page_Load); }
#endregion private void btnTest_Click(object sender, System.EventArgs e)
{
//Nothing
}
}
}
(2)在VS2005中新建一個頁面:
前臺HTML文件如下:<%@ 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:Label id="lblTest1" runat="server"> </asp:Label>
<asp:Label id="lblTest2" runat="server"> </asp:Label>
<asp:Label id="lblTest3" runat="server"> </asp:Label>
<asp:Button id="btnTest" runat="server" Text="回傳" OnClick="btnTest_Click1"></asp:Button>
</div>
</form>
</body>
</html>后臺CS代碼如下:using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!this.Page.IsPostBack)
{
this.PadColor();
}
}
private void PadColor()
{
this.lblTest1.BackColor = System.Drawing.Color.Red; //OK this.lblTest2.BackColor = System.Drawing.Color.FromName("Red"); //OK //回傳后色彩丟失!
this.lblTest3.BackColor = System.Drawing.Color.FromName("#FF0000");
} protected void btnTest_Click1(object sender, EventArgs e)
{
//Nothing
}
}第一個回答正確者,至少有40分奉送!
新建一個頁面,頁面中有三個Label,一個Button
在頁面第一次加載時,通過三種方法為上述三個Label加紅色底(BackColor)
上述Button事件中僅僅用來回傳頁面。
【問題】
在VS2003中,在點擊Button后,三個Label的底色都沒有丟失
在VS2005中,在點擊Button后,前兩個Label的底色沒有丟失,但第三個Label的底色卻丟失了!!
請高手指點,為什么會這樣?【我的操作】(1)在VS2003中新建一個頁面,前臺HTML文件如下:<%@ Page language="c#" Codebehind="Test3.aspx.cs" AutoEventWireup="false" Inherits="pm.Test3" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>Test3</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<asp:Label id="lblTest1" runat="server"> </asp:Label>
<asp:Label id="lblTest2" runat="server"> </asp:Label>
<asp:Label id="lblTest3" runat="server"> </asp:Label>
<asp:Button id="btnTest" runat="server" Text="回傳"></asp:Button>
</form>
</body>
</HTML>后臺CS代碼如下:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;namespace pm
{
public class Test3 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Label lblTest2;
protected System.Web.UI.WebControls.Label lblTest3;
protected System.Web.UI.WebControls.Button btnTest;
protected System.Web.UI.WebControls.Label lblTest1;
private void Page_Load(object sender, System.EventArgs e)
{
if(!this.Page.IsPostBack)
{
this.PadColor() ;
}
}
private void PadColor()
{
this.lblTest1.BackColor = System.Drawing.Color.Red; //OK this.lblTest2.BackColor = System.Drawing.Color.FromName("Red"); //OK //回傳后色彩并沒有丟失
this.lblTest3.BackColor = System.Drawing.Color.FromName("#FF0000");
} #region Web Form 設計工具產生的程式碼
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 此為 ASP.NET Web Form 設計工具所需的呼叫。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 此為設計工具支援所必須的方法 - 請勿使用程式碼編輯器修改
/// 這個方法的內容。
/// </summary>
private void InitializeComponent()
{
this.btnTest.Click += new System.EventHandler(this.btnTest_Click);
this.Load += new System.EventHandler(this.Page_Load); }
#endregion private void btnTest_Click(object sender, System.EventArgs e)
{
//Nothing
}
}
}
(2)在VS2005中新建一個頁面:
前臺HTML文件如下:<%@ 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:Label id="lblTest1" runat="server"> </asp:Label>
<asp:Label id="lblTest2" runat="server"> </asp:Label>
<asp:Label id="lblTest3" runat="server"> </asp:Label>
<asp:Button id="btnTest" runat="server" Text="回傳" OnClick="btnTest_Click1"></asp:Button>
</div>
</form>
</body>
</html>后臺CS代碼如下:using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!this.Page.IsPostBack)
{
this.PadColor();
}
}
private void PadColor()
{
this.lblTest1.BackColor = System.Drawing.Color.Red; //OK this.lblTest2.BackColor = System.Drawing.Color.FromName("Red"); //OK //回傳后色彩丟失!
this.lblTest3.BackColor = System.Drawing.Color.FromName("#FF0000");
} protected void btnTest_Click1(object sender, EventArgs e)
{
//Nothing
}
}第一個回答正確者,至少有40分奉送!
解决方案 »
- 求助` 关于数据展示控件的绑定问题` 在线等`
- 用vbscript修改sql数据库中已发布数据的时间
- 求网页数据抓取的方法和思路
- gft
- 请问:多文件下载或者导出问题
- Response.Redirect可以用;Page.RegisterStartupScript为什么就有问题》?
- 修改SQL表中数据的问题
- 水晶报表的发布问题?我做好了个网站,但是找不到水晶报表的可发性主键老是出问题,请问各位高手能否提供水晶报表的可发性主键的下载地址
- 如何在.CS代码里动态控制控件的位置?
- 配置问题,在线等待?分不够再加!
- 水晶报表 IIS发布问题!!!十万火急
- 帮我看看这个ASP.NET的需求问题怎么解决啊?
Color.FromName
只能翻译标准颜色,如Red,blue之类,但是翻译#ff0000会返回0
ColorTranslator.FromHtml
能翻译数字格式和翻译标准颜色,#ff0000
试下这个。
public static Color FromName(
string name
)
Visual C++
public:
static Color FromName(
String^ name
)
J#
public static Color FromName(
String name
)
JScript
public static function FromName(
name : String
) : Color
参数
name
类型:System..::.String作为预定义颜色名称的字符串。有效名称与 KnownColor 枚举的元素名称相同。返回值
类型:System.Drawing..::.Color此方法创建的 Color。备注
预定义颜色又称为已知颜色,由 KnownColor 枚举的一个元素表示。[color=#FF0000]/如果 name 参数不是预定义颜色的有效名称,那么 FromName 方法将创建一个 ARGB 值为 0(即所有的 ARGB 分量都为 0)的 Color 结构。
[color]
System.Drawing.Color.FromName("#FF0000");应该返回黑色!