I am new at vb .net and I want to know how to make website in it? like connect two papes or using header in different file and linking it together etc..

for some reason when I create a page than vb studio automatic adds a form tag and creates two files(aspx and aspx.vb files). I am not sure if I need aspx.vb when making websites.

header.aspx

since menu is always same in all pages. it would be good idea to put the code in different file and include when you need it.

<html> 
    <body> 
    <form...> 
        <div> 
            <% simple menu. %> 
            <a href="page1.aspx"> home </a> 
            <a href="page2.aspx"> page 2 </a> 
        </div> 
    </form> 
 </body> 
</html>
page1.aspx

this will be main or home page

<html> 
    <body> 
        <form...> 
            <div> 
            <!-- header fiel --> 
            <%          
                  Response.WriteFile ("header.aspx")
               %> 
            </div> 
        </form> 
   </body> 
</html>
page2.aspx
<html> 
    <body> 
        <form...> 
            <div> 
            <!-- header fiel --> 
            <%          
                  Response.WriteFile ("header.aspx")
               %> 
            </div> 
        </form> 
   </body> 
</html>

Dani AI

Generated

you are building an ASP.NET Web Forms app. Visual Studio creates two files per page on purpose: page.aspx (markup) and page.aspx.vb (code-behind). They are two halves of one partial class. Put HTML and server controls in .aspx; handle events (e.g., button clicks, redirects) in .aspx.vb. You can technically inline VB in the .aspx, but code-behind keeps things cleaner and easier to maintain, as hinted.

To reuse a header/navigation across pages, do not Response.WriteFile("header.aspx"). Use a Master Page and, optionally, a Web User Control for the header:

  • Add a Master Page (Site.Master). Put your single server form here and a content placeholder.
  • Add a Web User Control (Controls/Header.ascx) for the menu. Do not include <html>, <body>, or <form> in a user control.
  • Register and place the header control in the master, then create content pages that use the master.

Example (minimal):

<%@ Master Language="VB" CodeFile="Site.master.vb" Inherits="SiteMaster" %>
<%@ Register Src="~/Controls/Header.ascx" TagPrefix="uc" TagName="Header" %>
<!DOCTYPE html>
<html><body>
<form id="form1" runat="server">
  <uc:Header ID="Header1" runat="server" />
  <asp:ContentPlaceHolder ID="Main" runat="server" />
</form>
</body></html>
<%@ Page Language="VB" MasterPageFile="~/Site.Master" CodeFile="Page1.aspx.vb" Inherits="Page1" %>
<asp:Content ContentPlaceHolderID="Main" runat="server">
  <h1>Home</h1>
</asp:Content>

Troubleshooting tips:

  • Only one <form runat="server"> per page. Putting <form> tags in header/footer files causes nested-form issues.
  • Keep navigation links as plain <a href="~/Page2.aspx">Page 2</a>; use Response.Redirect("~/Page2.aspx") in code-behind when you need to navigate programmatically.
  • If a page has no server-side logic, the .aspx.vb can stay empty, but leaving it is fine.

Hi

Looking at the code that you have posted and the use of aspx and aspx.vb suggests that this is a WebForms web application. There are predominately two types (Web Forms and MVC) in the .NET Web arena. Currently, it looks like you are taking the classic ASP approach (using <% Response.Write.... %> style) which I would thoroughly recommend against.

Instead, with WebForms, Microsoft took a completely different approach in that they created a more event driven approach to developing web applications with the reason being that it would be easier for desktop developers to adopt .NET as a web platform. For this reason, the usual approach to developing a web forms application is to have two files (aspx and aspx.vb - or aspx.cs if using C#) which are actually partial classes. The aspx file is the designer file and is where you would include all of your HTML markup and control declarations (such as a button or data grid). The aspx.vb is the code behind file where all of the code would reside that responds to events from the UI.

If you want to include common page elements, such as header, navigation and footer then you would use a master file that contains this markup and reference that in your designer files.

Having said all of the above, if you are new to web programming in .NET then I would recommend that instead of starting with Web Forms, look at MVC. MVC (Model View Controller) is a design pattern with the goals of creating applications that are testable and follow a configuration over convention approach to development. It also tries to ensure a good separation of concerns pattern (although that is up to the developer to enforce). The ASP.NET MVC site contains some great introductory material and tutorials that should have you up and running in no time.

Finally, whether you use Web Forms or MVC, I would recommend getting a good beginners book on the subject. Just diving in and trying to get something to work is very difficult as there are so many pieces to each that you really do need a good grounding in the subject to create something that is usable and scalable.

HTH

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.