how to transfer a webpage from project to another in asp.net visual studio

HOUSSEM MAHJOUBI 286 Reputation points
2022-06-30T14:42:54.26+00:00

Hi members
i want transfer a webpage from project to another please help how i do that
i copied the 3 files the aspx+vb+designer
and when i opened i get error in every control like textbox label etc
please help

ASP.NET Core
ASP.NET Core
A set of technologies in the .NET Framework for building web applications and XML web services.
4,773 questions
{count} votes

Accepted answer
  1. Michael Taylor 56,856 Reputation points
    2022-06-30T15:25:59.42+00:00

    You didn't post the error so I'm not sure how we'll help.

    In general if you just drag the .aspx file within Solution Explorer from one project to another (or across VS instances) then it'll copy the subfiles. More importantly though it needs to set up the subtype on the child projects otherwise you end up with extra designers and things don't work. Open your project file in a text editor. The extra files need to be added as subtypes of the main file. If you drag and drop in Solution Explorer it handles this automatically. If you do it by hand then it might not.

       <Content Include="Index.aspx" />  
       <Compile Include="Index.aspx.cs">  
           <DependentUpon>Index.aspx</DependentUpon>  
           <SubType>ASPXCodeBehind</SubType>  
       </Compile>  
       <Compile Include="Index.aspx.designer.cs">  
           <DependentUpon>Index.aspx</DependentUpon>  
       </Compile>  
    

    However if you simply copied the files from one folder to another using file explorer then the files aren't even in your project. You need to add existing item to get them there.

    After the files are properly added to the project the next hurdle is probably the namespace. You need to edit each of the files and change the namespace references to whatever your new project is using. In the .cs files that will be the namespace blah line at the top of the file. You might also need to adjust your using statements. For the aspx file it'll have an attribute that references the codebehind file. That reference will be a full type name including namespace. Change it to match whatever your .cs file is now using.

    At that point the designer should successfully open and be hooked up. However you may still have compiler errors if your files are referencing things from the old project that you didn't bring across yet. You'll need to manually fix them up.

    1 person found this answer helpful.
    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Albert Kallal 5,496 Reputation points
    2022-07-02T18:47:27.08+00:00

    Ok, the steps are in general this:

    Open the project we wish to "import" into the web page into.

    Then, right click on your project explore, and choose add->add existing item.

    Browse to the aspx page in that project. Choose ONLLY the aspx page.

    Visual Studio will AUTOMATIC import the aspx, the aspx.vb, and the aspx.desinger.vb for you.

    Now, open the aspx page in design mode, you have to modify the top page, and change tthis:

    Inherits="MyOldeProjectName.WebForm3"   
    

    to

    Inherits="MyCalendar.WebForm3"

    In above, my new project name is MyCalendar.

    At that point, the page should now work.

    So, if you do this correctly, the Inherits part of the aspx page is all you need to update . Everything else now should work.

    So, the above is the least effort on your part. As noted, if you choose add->existing item, and browse to the older project for the web page to import? Only choose the aspx file - Visual studio will automatic import + pull in the other two files.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.