Search code examples
c#asp.netwebformsrunatserver

runat="server" Not Working?


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?


Solution

  • The attribute:

    runat="server"
    

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