common code behind pages

Discussion in 'ASP .Net' started by stumay111, Oct 2, 2005.

  1. stumay111

    stumay111 Guest

    I am working in VS 2003, using VB.NET.

    I have a series of pages with forms on them, an application for a DOT
    number for motor carriers. The code behind them iterates through the
    controls on the form, each of which have the same id as the field in
    the SQL Server database they post to, so I don't have to get the data
    from each field specifically.

    So I use the same code for each page. I have tried to set the
    CodeBehind to point to that page, but VS.NET keeps creating new
    <pagename>.aspx.vb pages when I create a new page and somehow attaches
    the page to the wrong CodeBehind. The project runs, but I keep getting
    compiler errors.

    In the old days, I'd just edit the make file... sigh.

    Where are these bogus pages getting attached?

    here's the compiler error:

    C:\Inetpub\wwwroot\MCCI\MCCIFormPg4.aspx.vb Unable to open module file
    'C:\Inetpub\wwwroot\MCCI\MCCIFormPg4.aspx.vb': The system cannot find
    the file specified.

    here's the CodeBehind statement from MCCIFormPg4.aspx:

    <%@ Page Language="vb" AutoEventWireup="false"
    Codebehind="MCCIForm.aspx.vb" Inherits="MCCI.MCCI"%>

    Not only that, but whenever I make a new page, it adds a new class to
    the list for that page. I don't want this - I want them to use the same
    class. I guess I should have made a distinct class to hold the code
    that parses the fields, and let VS.NET create it's own classes, and
    then imported the generic class into the page itself... maybe I should
    RTFM.
    stumay111, Oct 2, 2005
    #1
    1. Advertising

  2. Hi, Stu.

    re:
    > I want them to use the same class.
    > I guess I should have made a distinct class


    The best solution for this, in ASP.NET 1.1, is to compile your
    class file to an assembly, placing it in the bin directory,
    and importing the Namespace in your aspx pages.

    That allows you to instantiate your classes in any aspx page.

    In ASP.NET 2.0, you have a choice.

    You can either do the same as you do for ASP.NET 1.1,
    or you can place the class file ( *.vb or *.cs ) in the
    application's App_Code directory.

    ASP.NET 2.0 will compile any class file it finds there,
    and you can reference the namespace/classes in them in your aspx files.




    Juan T. Llibre, ASP.NET MVP
    ASP.NET FAQ : http://asp.net.do/faq/
    Foros de ASP.NET en Español : http://asp.net.do/foros/
    ======================================
    "stumay111" <> wrote in message
    news:...
    >I am working in VS 2003, using VB.NET.
    >
    > I have a series of pages with forms on them, an application for a DOT
    > number for motor carriers. The code behind them iterates through the
    > controls on the form, each of which have the same id as the field in
    > the SQL Server database they post to, so I don't have to get the data
    > from each field specifically.
    >
    > So I use the same code for each page. I have tried to set the
    > CodeBehind to point to that page, but VS.NET keeps creating new
    > <pagename>.aspx.vb pages when I create a new page and somehow attaches
    > the page to the wrong CodeBehind. The project runs, but I keep getting
    > compiler errors.
    >
    > In the old days, I'd just edit the make file... sigh.
    >
    > Where are these bogus pages getting attached?
    >
    > here's the compiler error:
    >
    > C:\Inetpub\wwwroot\MCCI\MCCIFormPg4.aspx.vb Unable to open module file
    > 'C:\Inetpub\wwwroot\MCCI\MCCIFormPg4.aspx.vb': The system cannot find
    > the file specified.
    >
    > here's the CodeBehind statement from MCCIFormPg4.aspx:
    >
    > <%@ Page Language="vb" AutoEventWireup="false"
    > Codebehind="MCCIForm.aspx.vb" Inherits="MCCI.MCCI"%>
    >
    > Not only that, but whenever I make a new page, it adds a new class to
    > the list for that page. I don't want this - I want them to use the same
    > class. I guess I should have made a distinct class to hold the code
    > that parses the fields, and let VS.NET create it's own classes, and
    > then imported the generic class into the page itself... maybe I should
    > RTFM.
    >
    Juan T. Llibre, Oct 2, 2005
    #2
    1. Advertising

  3. stumay111

    stumay111 Guest

    thanks for the quick answer! I suspected that would be the case... but
    wasn't sure of the mechanism (again... RTFM, Stuart)

    -s
    stumay111, Oct 2, 2005
    #3
  4. stumay111

    Mr Newbie Guest

    LOL

    I've had RTFM said to me so many times over the early years, that I
    eventually stopped asking for the most part.

    Regards Mr N.


    "stumay111" <> wrote in message
    news:...
    > thanks for the quick answer! I suspected that would be the case... but
    > wasn't sure of the mechanism (again... RTFM, Stuart)
    >
    > -s
    >
    Mr Newbie, Oct 2, 2005
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ben Miller [msft]

    Re: Code Behind vs. no code behind: error

    Ben Miller [msft], Jun 27, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    580
    Alphonse Giambrone
    Jun 28, 2003
  2. John

    Non-code behind to code behind

    John, Feb 19, 2007, in forum: ASP .Net
    Replies:
    2
    Views:
    482
    =?Utf-8?B?UGV0ZXIgQnJvbWJlcmcgW0MjIE1WUF0=?=
    Feb 19, 2007
  3. Denny
    Replies:
    1
    Views:
    776
  4. John Reye
    Replies:
    28
    Views:
    1,366
    Tim Rentsch
    May 8, 2012
  5. Jason Mellone
    Replies:
    3
    Views:
    92
    Jurko Gospodnetić
    May 7, 2014
Loading...

Share This Page