locked
Error when creating a Custom Object User Control (Controls do not exist in current context) RRS feed

  • Question

  • User-1018126932 posted

     Hello,

     I'm trying to create a User Control in VS 2008 and am getting the following two errors.  I'm a newbie and was hoping someone could help shed light on the code?

     Thanks,

    Error 1 The name 'LinkTable1' does not exist in the current context 

    Error 3 The name 'gridContent' does not exist in the current context 

     

    public partial class LinkTable : System.Web.UI.UserControl

    {

    protected void Page_Load(object sender, EventArgs e)

    {

    //Set the title

    LinkTable1.Title = "A List of Links";

    //Set the hyperlinked items

    LinkTableItem[] items = new LinkTableItem[3];

    items[0] = new LinkTableItem("Apress", "http://www.apress.com");

    items[1] = new LinkTableItem("Microsoft", "http://www.microsoft.com");items[2] = new LinkTableItem("ProseTech", "http://www.prosetech.com");

    LinkTable1.Items = items;

    }

     

     

    public class LinkTableItem

    {

    private string text;public string Text

    {

    get { return text; }

    set { text = value; }

    }

    private string url;public string Url

    {

    get { return url; }

    set { url = value; }

    }

    //Default constructor

    public LinkTableItem()

    { }

    public LinkTableItem(string text, string url)

    {

    this.text = text;this.url = url;

    }

    }

    public string Title

    {

    get { return lblTitle.Text; }set { lblTitle.Text = value; }

    }

    private LinkTableItem[] items;

    public LinkTableItem[] Items

    {

    get { return items; }

    set

    {

    items =
    value;

    //Refresh Grid

    gridContent.DataSource = items;

    gridContent.DataBind();

    }

    }

    }

    Sunday, April 27, 2008 1:00 PM

Answers

  • User-1136466523 posted

    Hi,

    <?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p> </o:p>

    Based on your code and the error message, it indicates that the application failed to find the object instance which named as LinkTable1 and gridContent.

    <o:p> </o:p>

    From the html code you provided, I still can’t find the controls with the ID mentioned above. So please make sure that the ID you are using in the code behind matches the control on the source mode page.

    <o:p> </o:p>

    Thanks.

     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, April 29, 2008 1:53 AM

All replies

  • User1001868398 posted

    Can you post the code of the usercontrol html? that message normally tell us that there is something wrong with the defenition of the control.

    Sunday, April 27, 2008 3:30 PM
  • User-1018126932 posted

    Sure thing. The html code for the control is:

     

    <%@ Control Language="C#" AutoEventWireup="true" CodeFile="LinkTable.ascx.cs" Inherits="LinkTable" %>

    <table border="1" cellpadding="2" style="width: 211px; height: 80px">

    <tr>

    <td>

    <asp:Label ID="lblTitle" runat="server" ForeColor="#C00000" Font-Bold="True" Font-Names="Verdana"

    Font-Size="Small" Text="A List of Links"></asp:Label>

    </td>

    </tr>

     

    <tr>

    <td>

    <asp:GridView ID="gridLinkList" runat="server" style="z-index: 1; left: 12px; top: 95px; position: absolute; height: 133px; width: 187px"

    AutoGenerateColumns="False" GridLines="None" onselectedindexchanged="gridLinkList_SelectedIndexChanged" ShowHeader="False">

    <Columns>

    <asp:TemplateField>

    <ItemTemplate>

    <img height="23" src="Water lilies.jpg" alt="Menu Item" style="vertical-align:middle" />

    <asp:HyperLink ID="lnk" NavigateUrl='<%# DataBinder.Eval(Container.DataItem, "Url" %>'

    runat="server" Font-Names="Verdana" Font-Size="X-Small" ForeColor="MediumBlue"

    Text='<%# DataBinder.Eval(Container.DataItem, "Text") %>'>HyperLink</asp:HyperLink>

     

    </ItemTemplate>

    </asp:TemplateField>

    </Columns>

    </asp:GridView>

    </td>

    </tr>

    </table>

    Monday, April 28, 2008 11:34 AM
  • User-1136466523 posted

    Hi,

    <?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p> </o:p>

    Based on your code and the error message, it indicates that the application failed to find the object instance which named as LinkTable1 and gridContent.

    <o:p> </o:p>

    From the html code you provided, I still can’t find the controls with the ID mentioned above. So please make sure that the ID you are using in the code behind matches the control on the source mode page.

    <o:p> </o:p>

    Thanks.

     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, April 29, 2008 1:53 AM