Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

BEGINNER QUESTION - Why won't this work?

Status
Not open for further replies.

MoaTad

Programmer
Jun 7, 2002
27
US
Hi,

I'm just trying out ASP.net and got this code from a book. For some reason, &quot;Hello World!&quot; will not print. Actually, no code that I put within the &quot;<% --- %>&quot; brackets is executed.

Basically, I just started a new project and then added the &quot;<% Response.Write(&quot;Hello World!&quot;) %>&quot; part.

I am developing in the Microsoft Development Environment 2002 v7.0.9466 and running Microsoft .Net Framework 1.0 v1.0.3705 all on Windows XP Pro.

What am I doing wrong?

Thanks in advance!


<%@ Page Language=&quot;vb&quot; AutoEventWireup=&quot;false&quot; Codebehind=&quot;WebForm1.aspx.vb&quot; Inherits=&quot;WebApplication1.WebForm1&quot;%>
<!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0 Transitional//EN&quot;>
<HTML>
<HEAD>
<title>WebForm1</title>
<meta name=&quot;GENERATOR&quot; content=&quot;Microsoft Visual Studio.NET 7.0&quot;>
<meta name=&quot;CODE_LANGUAGE&quot; content=&quot;Visual Basic 7.0&quot;>
<meta name=&quot;vs_defaultClientScript&quot; content=&quot;JavaScript&quot;>
<meta name=&quot;vs_targetSchema&quot; content=&quot; </HEAD>
<body MS_POSITIONING=&quot;GridLayout&quot; bgcolor=&quot;#ffffcc&quot;>
<%
Response.Write(&quot;Hello World!&quot;)
%>
</body>
</HTML>
 
Because that looks like asp....

add that line to your code behind....
WebForm1.vb.cs

Response.Write(&quot;Hello World&quot;)

to your PageLoad event....
 
Thanks wsmall73,

I am new to ASP.Net, but my understanding is that the code-behind page is WebForm1.aspx.vb.

I tried putting it in the PageLoad event and it still doesn't work.

I got the code from the book, &quot;ASP.Net Bible&quot; in Chapter 2, &quot;Getting Started with ASP.Net&quot;. They describe the ASP code being put in the WebForm1.aspx file. Actually, the book goes on to show more complex ASP code interleaved with the HTML in this file. Pretty much exactly as it is done in good-old-fashoned ASP. So I am pretty confident that I am working in the correct file.
But for some reason, the ASP code is not being interpreted at runtime.
At first I thought that &quot;building&quot; the solution was the answer, but I do that with no effect. Also, the book never mentions the necessity of building the solution.

Am I missing something?

Thanks


 
With old school spaggetti code you don't need to compile. However, it is highly recommended that you step away from spaggettie code and use the code behind method. Provides a much cleaner way to create your pages. If your using VS.NET it may get grouchy at you for trying to code using spaggetti code. VS.NET is built to use code behind pages.

Using VS.NET create a project. That project will automatically have a page called webform1 in it.
Go to the code behind file. In the Page_Load method type
Response.Write(&quot;Hello World&quot;) -- VB
Response.Write(&quot;Hello World&quot;); -- C#

Build your project (a build gathers resources, updates references and compiles the project)

Run your web page.

You should now see a blank page with &quot;Hello World&quot; at the top.

Note: Response.Write is really only usefull for debugging since it writes the text at the top of the outgoing html stream. Meaning you final page source looks like...
Hello World
<!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0 Transitional//EN&quot; >
<HTML>
<HEAD>
<title>Welcome To North America's Online Truck Stop!</title>
<meta content=&quot;Microsoft Visual Studio 7.0&quot; name=&quot;GENERATOR&quot;>
<meta content=&quot;C#&quot; name=&quot;CODE_LANGUAGE&quot;>
<meta content=&quot;JavaScript&quot; name=&quot;vs_defaultClientScript&quot;>
<meta content=&quot; name=&quot;vs_targetSchema&quot;>
<LINK href=&quot;Default.css&quot; type=&quot;text/css&quot; rel=&quot;stylesheet&quot;>
</HEAD>
<body>
</body>
</HTML>

Instead use label controls (or somthing similiar) and change the text property on them

That'l do donkey, that'l do
[bravo] Mark
If you are unsure of forum etiquette check here faq796-2540
 
Thanks Zarcom,

There must be something wrong. I did exactly as you said (here is the code on the code-behind page).

************************************************************
Public Class WebForm1
Inherits System.Web.UI.Page

#Region &quot; Web Form Designer Generated Code &quot;

'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

End Sub

Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub

#End Region

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
Response.Write(&quot;Hello World&quot;)
End Sub

End Class
************************************************************


I bult the project and it showed &quot;Build: 1 succeeded, 0 failed, 0 skipped&quot;, and clicked on &quot;View In Browser&quot; from the &quot;File&quot; menu. I just got a white page with no text. I also tried it through a regular browser (//localhost/WebApplication2/WebForm1.aspx) with the same results.

With such simple and straightforward instructions not working, I have to wonder if something is not set up right. Does anyone have any idea of something I could have done incorrectly during the installation or something else that would generate this problem?

Thanks

 
hi, cjlarue

&quot;If you installed VS.net or framework before installing IIS. then the .aspx will not be recognized.&quot;

so, is there any solution to make .net framework recognize IIS

 
Yes the link above has the fix


Regards
Chuck LaRue
ADRS Computer Services
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top