.aspx
没问题的代码
<%@ Page Language="C#" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server"> protected void SubmitBtn_Click(object sender, EventArgs e)
{
Body.Attributes["bgcolor"] = ColorSelect.Value;
}
</script><html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>HtmlGenericControl Example</title>
</head><body id="Body"
runat="server"> <h3>HtmlGenericControl Example</h3> <form id="form1" runat="server">
<div>
<br />
Select a background color for the page: <br />
<select id="ColorSelect"
runat="server">
<option>White</option>
<option>LightBlue</option>
<option>LightGreen</option>
<option>Yellow</option>
</select> <input type="submit"
runat="server"
value="Apply"
onserverclick="SubmitBtn_Click" id="Submit1" />
</div>
</form> </body>
</html>--------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------
.aspx
报错的代码
错误名称:编译器错误消息: CS1928: “System.Web.UI.HtmlControls.HtmlGenericControl”不包含“Attributes”的定义,
并且最佳扩展方法重载“System.Xml.Linq.Extensions.Attributes(System.Collections.Generic.IEnumerable<System.Xml.Linq.XElement>
, System.Xml.Linq.XName)”的某些参数无效
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Test_Web1.aspx.cs" Inherits="Test_Web1" %><!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 id="Head1" runat="server">
<title>1234567</title>
</head>
<body id="Body1" runat="server">
<form id="form1" runat="server">
<div>
<h3>2314677</h3>
<h3> I love you !!</h3><p>
<asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" />
</div>
</form>
</body>
</html>
.csusing System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;public partial class Test_Web1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Body1.Attributes("bgcolor") = "White"; //报错
}
protected void Button1_Click(object sender, EventArgs e)
{
// Body1.Attributes("bgcolor") = "White";
}
}
为什么报错呀,如何解决?谢谢回答 菜鸟问题
没问题的代码
<%@ Page Language="C#" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server"> protected void SubmitBtn_Click(object sender, EventArgs e)
{
Body.Attributes["bgcolor"] = ColorSelect.Value;
}
</script><html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>HtmlGenericControl Example</title>
</head><body id="Body"
runat="server"> <h3>HtmlGenericControl Example</h3> <form id="form1" runat="server">
<div>
<br />
Select a background color for the page: <br />
<select id="ColorSelect"
runat="server">
<option>White</option>
<option>LightBlue</option>
<option>LightGreen</option>
<option>Yellow</option>
</select> <input type="submit"
runat="server"
value="Apply"
onserverclick="SubmitBtn_Click" id="Submit1" />
</div>
</form> </body>
</html>--------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------
.aspx
报错的代码
错误名称:编译器错误消息: CS1928: “System.Web.UI.HtmlControls.HtmlGenericControl”不包含“Attributes”的定义,
并且最佳扩展方法重载“System.Xml.Linq.Extensions.Attributes(System.Collections.Generic.IEnumerable<System.Xml.Linq.XElement>
, System.Xml.Linq.XName)”的某些参数无效
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Test_Web1.aspx.cs" Inherits="Test_Web1" %><!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 id="Head1" runat="server">
<title>1234567</title>
</head>
<body id="Body1" runat="server">
<form id="form1" runat="server">
<div>
<h3>2314677</h3>
<h3> I love you !!</h3><p>
<asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" />
</div>
</form>
</body>
</html>
.csusing System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;public partial class Test_Web1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Body1.Attributes("bgcolor") = "White"; //报错
}
protected void Button1_Click(object sender, EventArgs e)
{
// Body1.Attributes("bgcolor") = "White";
}
}
为什么报错呀,如何解决?谢谢回答 菜鸟问题
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货