3

I am using .NET2.0. Let's say a have 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 within 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

It all works fine.

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

Namespace mycustomnamespace

When doing that I would get a complier error:

Name 'txtInput' is not declared - as if the code was no longer connected to the page

Do i need to modify the aspx page to include the namespace?, What about the partial class?

1 Answer 1

7

Do i need to modify the aspx page to include the namespace?, What about the 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 name of the class in the codebehind and Blah.Foo is it's namespace. You would need to change it to

<%@ Page AutoEventWireup="false" Inherits="mycustomnamespace.Bar" %>
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks. Now when I choose "View Code Gen File" from the page menu the generated code includes the custom namespace
Also it seems that I needed to add the projectname on top of the namespace like Inherits="MyProjectName.mycustomnamespace.Bar"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.