문제

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?

도움이 되었습니까?

해결책

The attribute:

runat="server"

Is only effective when all the root to this element has this attribute.

다른 팁

I had this problem with web page controls. They were resolved when I changed my project from a Web Application to a Web Site. Please see Code behind does not recognize my control variable on its aspx page.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top