locked
src attribute in page directive causes me trouble RRS feed

  • Question

  • User297437924 posted

    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
        Inherits System.Web.UI.Page

    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.

    Friday, March 6, 2020 1:08 PM

Answers

  • User475983607 posted

    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.

    https://docs.microsoft.com/en-us/dotnet/visual-basic/programming-guide/program-structure/namespaces

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, March 6, 2020 1:32 PM

All replies

  • User475983607 posted

    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.

    https://docs.microsoft.com/en-us/dotnet/visual-basic/programming-guide/program-structure/namespaces

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, March 6, 2020 1:32 PM
  • User297437924 posted

    OK, I'll learn namespaces.   Thanks for the link.  In the meantime, I solved the problem by replacing 'src' by 'codefile'.   

    Friday, March 6, 2020 5:01 PM