Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Custom namespace for code behind .aspx page

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?

like image 914
kristof Avatar asked Apr 06 '26 16:04

kristof


1 Answers

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" %>
like image 106
Tom Ritter Avatar answered Apr 09 '26 05:04

Tom Ritter