CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Hybrid View

  1. #1
    Join Date
    Apr 2005

    Control out of context

    Hello everybody

    I`ve created a WebForms applications for learning purposes. I`ve placed two TextBoxes on my WebForm1 using the Visual Studio toolbox. The code is shown below :

    <asp:TextBox ID="txtFirstName" runat="server"></asp:TextBox>
    <br />
    Last Name:
    <asp:TextBox ID="txtLastName" runat="server"></asp:TextBox>
    <br />
    Now in the corresponding WebForm1.aspx.cs coding file I`m trying to export the functionality of these two controls by creating the attribute FullName

    public string FullName
    get { return txtFirstName.Text + " " + txtLastName.Text; }
    Unfortunately, when I compile my code I get the error :

    Error	1	The name 'txtFirstName' does not exist in the current context
    Shouldn`t the control be in context since I`m placing it on the same WebForm1 as the corresponding cs file?

  2. #2
    Join Date
    Jun 2005
    JHB South Africa

    Re: Control out of context

    Check that the following is in your project files...
    In the WebForm1.aspx on top.
    <%@ Control Language="cs" AutoEventWireup="false" CodeBehind="WebForm1.aspx.cs" Inherits="[Namespace].WebForm1" %>
    and in WebForm1.aspx.cs.
    Namespace [Namespace]
        Partial Public Class WebForm1
    Then dbl check that the Autogenerated WebForm1.aspx.designer.cs contains the following..
    Namespace [Namespace]
        Partial Public Class WebForm1
            Protected WithEvents txtFirstName As Global.System.Web.UI.WebControls.TextBox
    Articles VB6 : Break the 2G limit - Animation 1, 2 VB.NET : 2005/8 : Moving Images , Animation 1 , 2 , 3 , User Controls
    WPF Articles : 3D Animation 1 , 2 , 3
    Code snips: VB6 Hex Edit, IP Chat, Copy Prot., Crop, Zoom : .NET IP Chat (V4), Adv. ContextMenus, click Hotspot, Scroll Controls
    Find me in ASP.NET., VB6., VB.NET , Writing Articles, My Genealogy, Forum
    All VS.NET: posts refer to VS.NET 2008 (Pro) unless otherwise stated.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Windows Mobile Development Center

Click Here to Expand Forum to Full Width

On-Demand Webinars (sponsored)

We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.