cptully
cptully

Reputation: 697

why is asp:TextBox not accessible by ID in VB.net

I am new to VB.net (coming from C# and Java before that). I have taken over maintaining a legacy site that is written in a combination of VB.net and C#.

Today I have been trying to implement a new page on a section of the site the must be written in VB and I am struggling to make sens out of what is happening. I have compared my new code to existing code for working pages and cannot find any errors on my part but I must be missing something.

I created the base files using Visual Studio 2017's "Add New Item..." wizard and chose Webform with Masterpage. I selected the same masterpage that other pages in this area of the site use. I have deleted and recreated these files several time and the errors vary but all fall around the theme of "..is not declared. It may be inaccessible due to its protection level."

Here is my .aspx file:

<%@ Page Title="" Language="vb" AutoEventWireup="false" MasterPageFile="~/components/navigation/noajax.master" CodeBehind="default.aspx.vb" Inherits="_my.law.unc.edu._default" %>
<asp:Content ID="Content1" ContentPlaceHolderID="cphContent1" runat="server">
    <asp:UpdatePanel ID="upPage" UpdateMode="Conditional" ChildrenAsTriggers="true" runat="server">
        <ContentTemplate>
            <label for="<%=txtEamilSearch.ClientID %>">Email:</label><br />
            <asp:TextBox ID="txtEamilSearch" runat="server" />
            <asp:Button ID="butTest" Text="Change" OnClick="butTest_OnClick" runat="server" />
        </ContentTemplate>
    </asp:UpdatePanel>
</asp:Content>

and here is my code behind (.aspx.vb) file:

Namespace manage.alumni

    Public Class _default
        Inherits System.Web.UI.Page

        Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        End Sub

        Sub butTest_OnCLick(ByVal sender As Object, ByVal e As EventArgs)
            'this line is meant to change the content of the textbox 
            '  but I haven't gotten past the inability to recognize
            '  the control.
            txtEmailSearch
        End Sub
    End Class

End Namespace

My problem is that at the moment I am getting an error that "txtEmailSearch is not declared. It may be inaccessible due to its protection level".

I feel like I must be missing some very basic step here but an entire day of googling the error message and looking for VB.Net/ASP.Net examples has not turned up a useful answer.

Upvotes: 0

Views: 1012

Answers (2)

Jowe
Jowe

Reputation: 63

You have misspelled txtEmailSearch in your aspx file. Fix it or copy and paste the name from your code behind file.

Upvotes: 1

SpruceMoose
SpruceMoose

Reputation: 10320

Look at this line:

<%@ Page Title="" Language="vb" AutoEventWireup="false" MasterPageFile="~/components/navigation/noajax.master" CodeBehind="default.aspx.vb" Inherits="_my.law.unc.edu._default" %>

Your Inherits attribute value should match the name of your code-behind class i.e. _default or manage.alumni._default

Upvotes: 2

Related Questions