最近使用VS2008開發網頁compiler遇到一個怪問題
最近使用VS2008開發網頁遇到一個怪問題
環境是這樣的,在一個Web專案裡有一支(AAA.aspx,AAA.aspx.cs)的網頁,裡面有兩個GridView
AAA.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="AAA.aspx.cs" Inherits="AAA" %>
<!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:GridView ID="GridView1" runat="server">
</asp:GridView>
<asp:GridView ID="GridView2" runat="server">
</asp:GridView>
</div>
</form>
</body>
</html>AAA.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 AAA : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
this.GridView1.DataSource = new string[] { "" };
this.GridView2.DataSource = new string[] { "" };
}
}結果compiler出現這樣的錯誤,直接執行網頁不會報錯
VS也是可以點出GridView2這個控制項的
好奇怪喔,是不是VS的Bug呢,後來我在這個Web專案裡找到另一支網頁AAATemp.aspx,原來這支是AAA.aspx備份過來的
AAATemp.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="AAA.aspx.cs" Inherits="AAA" %>
<!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:GridView ID="GridView1" runat="server">
</asp:GridView>
</div>
</form>
</body>
</html>這支AAATemp.aspx的確只有一個GridView
而且它的 CodeFile="AAA.aspx.cs" Inherits="AAA"
所以在comipler時也會找AAA.aspx.cs所以才會出現這個問題
用VS點那個錯誤訊息,是跳到AAA.aspx.cs所以才會以為VS是不是有Bug呢..這下終於真相大白了.

