tags:

views:

33

answers:

3

This is my link button:-

<asp:LinkButton ID="lnk1" Text="Set as Default" runat="server" Visible="false" OnClick="lnk1_OnClick"></asp:LinkButton>

In Code Behind I am simply making it visible

lnk1.Visible = true;

I have checked the IDs over n over..whats wrong ? Intellisense wont detect it either..I am doing something really silly..just cant figure what it is ..help!

I even restarted Visual Studio..still same error

+2  A: 

Sometimes the designer class is not re-generated correctly. Things you can try:

  • select the line, cut, save, rebuild, paste back, save
  • delete the designer .cs file, right click the aspx, convert to web application -> this will generate the designer class from scratch
CyberDude
A: 

Since I do not have the rights to comment; so ...

  • In which event you are making that item visible? try doing that in PageLoad.
  • Can you show your markups?

Alternatively, you can try to Find the control.

John
it wouldn't be a compile error but a potential null reference exception if that was the case
Rune FS
+4  A: 

Is the contol part of another control template? E.G. part of a repeaters ItemTemplate etc?

Update:

Since OP has said it's part of a repeaters ItemTemplate, just thought I'd explain what to do (Even though OP has sorted it)

You need to call FindControl on the Repeater, or Controls.OfType() depending on the situation, to get the control.

ASP:

    <asp:Repeater runat="server" ID="rptrTest">
        <ItemTemplate>
            <asp:TextBox runat="server" ID="txtBxName" />
            <asp:CheckBox runat="server" ID="chkBx1" />
            <asp:CheckBox runat="server" ID="chkBx2" />
        </ItemTemplate>
    </asp:Repeater>

C#

        IEnumerable<CheckBox> chkBoxes = rptrTest.Controls.OfType<CheckBox>();
        TextBox txtBxName = (TextBox)rptrTest.FindControl("txtBxName");

What I'll often do for commonly used controls (though wether it's a good idea or not I'm sure someone will now let me know), is create a member which executes this code.

    private TextBox _txtBxName;
    public TextBox txtBxName {
        get {
            if (_txtBxName == null) {
                _txtBxName = (TextBox)rptrTest.FindControl("txtBxName");
            }
            return _txtBxName;
        }
    }
Psytronic
Yes its inside of ItemTemplate of Repeater control..so now what ?
Serenity
ok I have kinda figured it out...thnx all
Serenity
LOL, small but essential detail...
CyberDude