Custom namespace for code behind .aspx page

I am using .NET2.0. Let them say that a has a simple aspx form with txtInput and btnSomeAction

   <asp:TextBox ID="txtInput" runat="server"></asp:TextBox>
   <asp:Button ID="btnSomeAction" runat="server" CommandName="SomeAction" Text="Do"/>

Then in the code behind the form I have

Protected Sub btnSomeAction_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSomeAction.Click
    Dim s As String
    s = txtInput.Text
End Sub

Everything works perfectly.

Then I want to add code to a custom namespace, like

Namespace mycustomnamespace

In doing so, I get a complier error:

The name 'txtInput' is not declared - as if the code is no longer connected to the page

Do I need to modify an aspx page to include a namespace ?, What about a partial class?

+3
source share
1 answer

Do I need to modify an aspx page to include a namespace ?, What about a partial class?

Yes. At the top of your aspx file, you should see something like

<%@ Page AutoEventWireup="false" Inherits="Blah.Foo.Bar" %>

Where bar is the class name in the code, and Blah.Foo is the namespace. You will need to change it to

<%@ Page AutoEventWireup="false" Inherits="mycustomnamespace.Bar" %>
+7

All Articles