3

I have the following markup on my ASCX control:

<a href="ProposalDetails.aspx?pid=<%= Request.QueryString["pid"] %>&tab=Proposal&view=RoomBlock" id="RoomBlockLink" runat="server">
    Room Block
</a>

It seems to work fine, but if I attempt to modify this control from C# code:

RoomBlockLink.Attributes.Add("style", "color: #808080; font-style: italic;");

I get the Intellisense and compiler error:

The name 'RoomBlockLink' does not exist in the current context

What am I missing?

4

2 回答 2

7

属性:

runat="server"

仅当此元素的所有根都具有此属性时才有效。

于 2013-11-04T20:01:25.693 回答
0

我在网页控件方面遇到了这个问题。当我将我的项目从 Web 应用程序更改为网站时,它们得到了解决。请参阅Code behind does not identify my control variable on its aspx page

于 2013-11-04T20:07:32.057 回答