views:

859

answers:

1

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?

+5  A: 

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" %>
Tom Ritter
Thanks. Now when I choose "View Code Gen File" from the page menu the generated code includes the custom namespace
kristof
Also it seems that I needed to add the projectname on top of the namespace like Inherits="MyProjectName.mycustomnamespace.Bar"
kristof