Reputation: 3424
I did type runat="server" in the label tag. its still not accessible.
I did copy this label from another webform. I've noticed when copying labels from others webforms, sometimes they are not accessible. What is the problem?
Upvotes: 0
Views: 1140
Reputation: 14600
It's because your code behind class is missing reference to that control. You guess you dont have .designer with your page class, right? Then you have to "map" that control manually
YOu can definie class variable like Label myLabel
and then later in Page_Load
you have to use myLabel = Find('myLabelId')
function, to map that label. (This might not be 100% accurate syntax).
Edit: Asuming your label has ID="Label2", code should look like:
Label _label2;
Page_Load(
// some code
_label2 = (Label)FindControl("Label2");
)
Upvotes: 0
Reputation: 25495
Check your designer code and see if its in there. If its not your markup and designer are out of sync unless of course you have the control in a template. I have ran into this issue recently and fixed it by just adding a literal control forcing the designer to regen and then deleting the literal.
Upvotes: 4
Reputation: 3974
from what you have given here, I see you typed runat=server without quotations.
try adding quotations and check again.
runat="server"
full example
<asp:label runat="server" ID="Label1" >Label1</asp:Label>
Upvotes: 0