locked
How can I make a "bare bones" ASP.net (aspx) Hello world web page? RRS feed

  • Question

  • I have IIS7 and I am able to display .html files so that works.... I belive ASP is working on it.

    I dont want to use the visual studio yet because it is way too abstruse and out of my leage for now.

    So can you give me thie minimum requirments for  what it needs to display in IIS rootwww

    i think it needs a default.aspx and a config file and one other thing... I triedand always get errors
    so if you can make the seperate files that i can  cut and paste and run off server that would really help me understand.

    I know you have to crawl before you walk and walk before you run, but i like to see what its like to run first ;)

    Thursday, May 3, 2012 3:25 AM

Answers

  • Also everytime I try to export what i made to my iis server nothing works.... And is there any better forums out there where asp.net is more applied or used?

    --EDIT--

    Just incase anyone else if haveing a difficult time jumping from C# console apps to ASP IIS

    The top of the ASPX page must have your language you want to use
    <%@ Page Language="C#"%>

    The rest is HTML with (C#... Java... CSS......)

    But like php to incule your C# code inside the ASPX(html) just escape it by typing
    <% YOUR  C#, VB..... CODE HERE %>

    Here is a cool example i finally found that is not overly comlicated

    <%@ Page Language="C#"%> 
     <html>
     <head>
     <title>Hello World!</title>
     </head>
     <body>
    
       <% for (int i=1; i <7; i++) 
    	{ %>
          <font size="   <%=i%>"> C# inside aspx! </font> <br>
       <%   }
       Response.Write("<p><cite>COOL</cite>");
       %>
    
     </body>
     </html>
    

    Thursday, May 3, 2012 6:57 PM

All replies

  • Also everytime I try to export what i made to my iis server nothing works.... And is there any better forums out there where asp.net is more applied or used?

    --EDIT--

    Just incase anyone else if haveing a difficult time jumping from C# console apps to ASP IIS

    The top of the ASPX page must have your language you want to use
    <%@ Page Language="C#"%>

    The rest is HTML with (C#... Java... CSS......)

    But like php to incule your C# code inside the ASPX(html) just escape it by typing
    <% YOUR  C#, VB..... CODE HERE %>

    Here is a cool example i finally found that is not overly comlicated

    <%@ Page Language="C#"%> 
     <html>
     <head>
     <title>Hello World!</title>
     </head>
     <body>
    
       <% for (int i=1; i <7; i++) 
    	{ %>
          <font size="   <%=i%>"> C# inside aspx! </font> <br>
       <%   }
       Response.Write("<p><cite>COOL</cite>");
       %>
    
     </body>
     </html>
    

    Thursday, May 3, 2012 6:57 PM
  • In general you don't want to be using scriplets for your aspx pages.  You're best of having an aspx page with nothing but markup code, and then a code behind (i.e. regular .cs or .vb file) that modifies that markup.  Visual Studio makes this much easier by taking care of wiring all of this up for you when you make a new page/user control.  You can do it by hand, but it's annoying and few people ever bother to do it.

    You also generally shouldn't be using "Response.Write" and writing to the stream directly, you should be modifying/creating Controls on the page and letting them render themselves.

    Here's a simple hello world example using this model.  Note this is SharePoint, not plain ASP, because that's what I have up right now, but the important stuff will be the same.

    In DemoToSukmi.aspx:

    <%@ Assembly Name="$SharePoint.Project.AssemblyFullName$" %>
    <%@ Register TagPrefix="asp" Namespace="System.Web.UI" Assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" %>
    
    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="DemoToSukmi.aspx.cs" Inherits="Testing.Layouts.Testing.DemoToSukmi"
        DynamicMasterPageFile="~masterurl/default.master" %>
    
    <asp:Content ContentPlaceHolderID="PlaceHolderMain" runat="server">
        <asp:Label ID="someLabel" Text="Text Goes Here"  runat="server"/>
        <asp:Button ID="someButton" Text="Click Me!" runat="server" />
    </asp:Content>
    

    In DemoToSukmi.aspx.cs:

    using System;
    using Microsoft.SharePoint;
    using Microsoft.SharePoint.WebControls;
    
    namespace Testing.Layouts.Testing
    {
        public partial class DemoToSukmi : LayoutsPageBase
        {
            protected void Page_Load(object sender, EventArgs e)
            {
                someButton.Click += new EventHandler(someButton_Click);
            }
    
            private void someButton_Click(object sender, EventArgs e)
            {
                someLabel.Text = "Hello World!";
            }
        }
    }
    

    Thursday, May 3, 2012 7:38 PM