Results 1 to 10 of 10

Thread: Reusing an existing form in a new project

  1. #1

    Thread Starter
    Hyperactive Member MarkusJ_NZ's Avatar
    Join Date
    Jun 2001
    Posts
    375

    Reusing an existing form in a new project

    Hi all,

    How can I go about importing into a new project a form that exists in another project?

    What I have is a textbox that allows people to change their information and I would like to 're-use' this form and it's functionality in a new project that I am creating.

    I have tried adding a reference to the existing project and then creating an instance of the form but the form name does not appear in the intellisense..

    Example is

    Project 2 (NewProject) references Project 1(OldProject)

    VB Code:
    1. ' Then I tried in the new project
    2. Dim oProj as new OldProject.ExistingForm

    I was hoping that I could do the above and then when a user clicked a button display the form from the old project and therefore re-use the form..

    Can this be done and if so, how do I go about doing it??

    Thanks
    MarkusJ

  2. #2
    PowerPoster hellswraith's Avatar
    Join Date
    Jul 2002
    Location
    Washington St.
    Posts
    2,464
    You can't create an instance of the page itself to show because it is a mix of HTML and code. The other reason is because ASP.Net is stateless.

    What you can do if you really don't want to copy and paste (which is the easiest solution for you), is redirect to that page. Then in the destination page, have a way to tell where the user came from to do different actions based on that.

    This only applies for pages though. You can include controls that you have in another project I believe. You can also use components and other classes you have in other projects.

  3. #3
    Addicted Member
    Join Date
    Apr 2002
    Posts
    235
    You don't even need to copy and paste if you're using vs.net. Just open up the solution explorer and right click on the project. Select add existing item, browse to your file and vs will automatically copy it into your directory. Easy.

  4. #4
    PowerPoster hellswraith's Avatar
    Join Date
    Jul 2002
    Location
    Washington St.
    Posts
    2,464
    It is easy, but then in the code, if there is redirections or whatever, you will have to change it to make it work with your current project, and in turn, maybe disrupting the other project.

    I think it is best to just create a new page. It doesn't take up too much space, and you can configure it exactly like you want it. Copy and paste the code you need, or just create a common class that both pages access to do the processing.

    I am just thinking about the maintainability of the site.

  5. #5
    Addicted Member
    Join Date
    Apr 2002
    Posts
    235
    I might be misunderstanding you, but VS makes another copy on your hd and puts it in your current project's folder. Unless vs is doing something wacky, changes to the new copy won't affect the old copy. Unless I'm missing something.

    Confused now.

  6. #6
    PowerPoster hellswraith's Avatar
    Join Date
    Jul 2002
    Location
    Washington St.
    Posts
    2,464
    Ok, I didn't know it created a copy of the code behind page, I thought it just made a copy of the html part of it and linked to the old code behind page. Thanks for the info, that for sure would be the easy way to do it then. Then you are free to make any modifications necessary.

  7. #7

    Thread Starter
    Hyperactive Member MarkusJ_NZ's Avatar
    Join Date
    Jun 2001
    Posts
    375
    Cool, thanks for your help
    Cheers
    Markus

  8. #8
    Addicted Member
    Join Date
    Apr 2002
    Posts
    235

    egg all over my face

    Ooops, well, er, I didn't even think about the codebehind file. Dangit. You can try adding it seperately, but I tried it and it's not working for some reason.

    Sorry.

  9. #9
    Hyperactive Member
    Join Date
    Jan 2003
    Location
    Cape Cod, US
    Posts
    292
    In some ways I'm glad I'm not the only one to have this problem as it has been a pain in the neck for me too.

    The way I'm managing it right now is through setting-up Visual Source Safe to share these files.
    This way when project A makes a change to a file, the same change is reflected in Project B's copy.

  10. #10
    PowerPoster hellswraith's Avatar
    Join Date
    Jul 2002
    Location
    Washington St.
    Posts
    2,464
    But if you create a project that just contains classes, not forms, and use those classes for the functionality of the page, you only have to edit at one place. Your web form should only contain UI type stuff and calls to the classes you built as I stated above. This way you can have many web forms accessing the same business logic. That is the way I was taught, and it seems to work pretty well for me.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width