Last post Mar 06, 2020 05:01 PM by RateFor
Mar 06, 2020 01:08 PM|RateFor|LINK
Suppose I have a page directive such as:
<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="expt3.aspx.vb" src="expt3.aspx.vb" inherits="expt3" %>
The code behind page for this page has a class declaration as follows:
Public Class expt3
The designer page has a class declaration as follows:
Partial Public Class expt3
For some reason, this doesn't work. As soon as I the code in the code behind modifies a control (for instance 'textboxDollars.text = 99", I get a compile error.
Notice in the page directive that I put a 'src' attribute. This was not there originally, in fact what I had was an inherit attribute with a prefix (such as inherits="myProject.expt3"). I removed the prefix, and put in the src attribute.
But now it seems as if the class isn't connected to the aspx page any more.
The reason I did all this was to be able to move all my code into a folder of a different website, and if I had 'myProject." prefixes, then I would conflict with that other project. I wanted to save money on buying a whole new website.
Mar 06, 2020 01:32 PM|mgebhard|LINK
This is a duplicate thread.
As explained in your other threads, the item you are calling a prefix is actually a namespace. Namespaces lets you group code. In Web Forms the application name is the default namespace.
In fact, a unique namespace is exactly what you need to move the pages to another project because the namespace will keep the page class unique. Keep in mind, the designer file contains the server control members wrapped in a namespace. If you remove the
namespace from the page directive and not the designer file then the designer class members, the server controls, can no longer be found.
I recommend learning .NET namespaces rather than ignoring the language construct.
Mar 06, 2020 05:01 PM|RateFor|LINK
OK, I'll learn namespaces. Thanks for the link. In the meantime, I solved the problem by replacing 'src' by 'codefile'.