Question

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?

Was it helpful?

Solution

The attribute:

runat="server"

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

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top