Solved

ASP.NET Newbie: Howto - Display Data via The Response Object

Posted on 2004-08-17
13
293 Views
Last Modified: 2013-11-25
Greetings

I am reading Sams Teach Yourself ASP.NET in 21 days (yeah...right). BUT i JUST LOVE IT.

In this book there are several listings which demonstrate the reponse.write() method in asp.net. I cant seem to get ANY of them to work.  Here is my example (taken largely from the book...but I used Visual Studio.net [again ...in newbie mode] for the IDE.

The Problem is it does NOT generate an error. just that NOTHING displays on the page!?! ...what gives?

PLEASE READ THE ANSWER DISCLAIMER B4 YOU RESPOND ;->

=======[   code ]===========

<%@ Page Language="vb" AutoEventWireup="false" Codebehind="pageloadTest.aspx.vb" Inherits="WebApplication1.pageloadTest"%>

<script runat=server>
sub page_load(sender as object, e as eventargs)
dim i as integer
 response.write("this is an example")
 response.write("<hr width='100%' \>")
 'count to 5 and display text size change
 for i = 1 to 5
  response.write("<font size=" & i & ">Hi!<br></font>")
 next
end sub
</script>


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>pageloadTest</title>
<meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" content="Visual Basic .NET 7.1">
<meta name=vs_defaultClientScript content="JavaScript">
<meta name=vs_targetSchema content="http://schemas.microsoft.com/intellisense/ie5">
</head>
<body MS_POSITIONING="GridLayout">


</body>
</html>

=======[ / code ]=======


==========================
QUESTION/ANSWER DISCLAIMER
==========================

About Answers

Please note: I am a rookie, the "greenest" of greenhorns. When I submit a question what I am looking for is a clear understanding of WHAT I AM DOING WRONG (the theory). Many have supplied code samples with no explanation. I have found that this only helps SOMETIMES. If I don't understand the error - I (in my "green"-ness) - will most likely commit the same error over and over again UNTIL I UNDERSTAND why I keep committing the same error.

That being said... CODE ONLY ANSWERS WILL GET NO POINTS FROM ME! Not to be nasty, but again I'm trying to learn. So please, simply ADD A SENTENCE OR TWO EXPLAINING WHAT I'M DOING WRONG to help clear the fog.

About Points

I don't belive in giving ANYTHING less than 500 points because I consider EVERY question "extremely important". Important to either a project (yeah right) or my continued journey out of the land of the Newbie. On the other hand You Guys and Gals
already know this stuff and make money doing it, yet you still find the time to answer questions to the benefit of us all. Thats definitely worth 500 point to me.

Thank you for your patience and undertsanding

the_sleeper
0
Comment
Question by:the_sleeper
  • 6
  • 5
  • 2
13 Comments
 
LVL 25

Expert Comment

by:nauman_ahmed
ID: 11825781
Hey sleepy dude :),

Where are you getting the error? Also when I use codebehind as it is declared in the statement:

<%@ Page Language="vb" AutoEventWireup="false" Codebehind="pageloadTest.aspx.vb" Inherits="WebApplication1.pageloadTest"%>

I have to add the code in pageloadTest.aspx.vb file and not in the .aspx file.

Even if you want to declare it inline code in aspx, Page_Load will not be loaded since you are using code behind.

Cheers, nauman
0
 

Author Comment

by:the_sleeper
ID: 11825841
@nauman >> Where are you getting the error?

No error message. Just a blank page. VS states that the page "compiled" with no errors, nothing skipped (whatever that means)..

@nauman >> codebehind

1. havent gotten to code behind yet. ;-)
2. but the book shows the declarations as simply: <%@ Page Language="VB" %>
3. all the other stuff was automatically added using Visual Studio.net
0
 
LVL 25

Expert Comment

by:nauman_ahmed
ID: 11825863
So a typical helloworld.aspx will look like this:

<%@ Page language="c#" Codebehind="HelloWorld.aspx.cs" AutoEventWireup="false" Inherits="SampleWebProject.HelloWorld" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" > 

<html>
  <head>
    <title>HelloWorld</title>
    <meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
    <meta name="CODE_LANGUAGE" Content="C#">
    <meta name=vs_defaultClientScript content="JavaScript">
    <meta name=vs_targetSchema content="http://schemas.microsoft.com/intellisense/ie5">
  </head>
  <body MS_POSITIONING="GridLayout">
      
    <form id="Form1" method="post" runat="server">

     </form>
      
  </body>
</html>

and HelloWorld.aspx.cs (its in C# but easy to understand) will look like this:

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

namespace SampleWebProject
{
      /// <summary>
      /// Summary description for HelloWorld.
      /// </summary>
      public class HelloWorld : System.Web.UI.Page
      {
            private void Page_Load(object sender, System.EventArgs e)
            {
                  // Put user code to initialize the page here
                  Response.Write("this is an example");
                  Response.Write("<hr width='100%'>");
                  for (int i = 0;i<5;i++)
                  {
                        Response.Write("<font size='"+i+"'>Hi <br></font>");
                  }
            }

            #region Web Form Designer generated code
            override protected void OnInit(EventArgs e)
            {
                  //
                  // CODEGEN: This call is required by the ASP.NET Web Form Designer.
                  //
                  InitializeComponent();
                  base.OnInit(e);
            }
            
            /// <summary>
            /// Required method for Designer support - do not modify
            /// the contents of this method with the code editor.
            /// </summary>
            private void InitializeComponent()
            {    
                  this.Load += new System.EventHandler(this.Page_Load);
            }
            #endregion
      }
}

HTH, nauman
0
 
LVL 25

Expert Comment

by:nauman_ahmed
ID: 11825877
ok if you dont want to use codebehind you can format your page like that:

>>HelloWorld.aspx

<%@Page language="VB"%>
<script language="VB" runat="server">
sub page_load(sender as object, e as eventargs)
 dim i as integer
 response.write("this is an example")
 response.write("<hr width='100%' \>")
 'count to 5 and display text size change
 for i = 1 to 5
  response.write("<font size=" & i & ">Hi!<br></font>")
 next
end sub
</server>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>pageloadTest</title>
<meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" content="Visual Basic .NET 7.1">
<meta name=vs_defaultClientScript content="JavaScript">
<meta name=vs_targetSchema content="http://schemas.microsoft.com/intellisense/ie5">
</head>
<body MS_POSITIONING="GridLayout">


</body>
</html>

Remember this code is to be used in one .aspx file.

Best, Nauman
0
 

Author Comment

by:the_sleeper
ID: 11825916
@Nauman >>> Remember this code is to be used in one .aspx file

hmm. so this seems to be a Visual Studio thing (it just added all the extra attributes) .

Problem is, visual studio just ADDS the full declaration (and [i'm sure] the "aspx.cs" [code behind]) before I even get to enter a single character. So should I just use NotePad?
 
0
 
LVL 25

Assisted Solution

by:nauman_ahmed
nauman_ahmed earned 300 total points
ID: 11826110
Yes. You got it right buddy :)

-Nauman
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 25

Expert Comment

by:nauman_ahmed
ID: 11826114
Just copy and paste the HelloWorld.aspx code in the NotePad and save your file.

-Nauman
0
 
LVL 8

Accepted Solution

by:
shovavnik earned 200 total points
ID: 11826274
First of all, how you choose what a good answer is obviously your choice.  But, in my opinion, conditioning that answer is a bit nasty anyway, especially considering your seeming awareness of the time constraints under which people post responses.  In addition, there's no guarantee that if you DO get a detailed answer, it will help you out either.  We're here to help, but if you're trying to learn, you're gonna have to do the hard part.

That being said, the answer has already been posted, but I will add one minor point (not for points please).

You *can* avoid using Notepad or another editor.  There are a few buttons at the top of the Solution Explorer in the IDE.  One of them is to show all the files.  Click on it.  That will show you all the files in your projects' directories.

Note that your .aspx file has a [+] next to it now.  Expand it and you'll see the .vb and the .vb.resx files that are associated with that .vb file.  These are your code-behind and resource files, respectively.  If you select the .vb file and delete it, you'll be able to work in the IDE with your .aspx file and without the codebehind.  If I recall correctly, VS.NET even removes the CodeBehind attribute from the <% Page %> directive.

Also, you may want to consider using a simpler IDE.  There's a free IDE from Microsoft called Web Matrix which doesn't support code behind files and may make it simpler for you to learn.  Once you feel comfortable with it, then move up to VS.NET.  The problem is that VS.NET is a very very very rich IDE and can be very confusing for beginners.  (Plus it's free and legal.)

Good luck.
0
 

Author Comment

by:the_sleeper
ID: 11826339
shovavnik >> We're here to help, but if you're trying to learn, you're gonna have to do the hard part.
No offense meant,
1. i've had this answer  disclaimer (up for about a year now) to help those who would simply provide code-only answers to see my "green-ness" more clearly. Not one person has complained (until now) and it how I learned asp. That and a few good books. Check my history. I try to compensate by giving the max points for each question (heck i'm paying for it).

2. I've got several books, i'm reading everyday, im workin every example, and i'm asking questions. Is there someothwer "hard part" i'm missing?

Thanks for your response. It cleared up quite a bit.


0
 

Author Comment

by:the_sleeper
ID: 11826348
Thanks to everyone who responded. I'll try harder!
0
 

Author Comment

by:the_sleeper
ID: 11826359
whoops shovanik, I awarded you points anyway. because the problem I'm experiencing is MORE one of the manipulation of the VS IDE...and you dealt (specifically) with that. But nauman_ahmed cleared away some of the fog...so (more) points to him. hope no ones offended. thanks again!
0
 
LVL 8

Expert Comment

by:shovavnik
ID: 11826419
Thanks for the points.

I'll leave it to cultural differences.  (I'm not from the States.)  I guess I misconstrued your intent.

Happy coding!
0
 
LVL 25

Expert Comment

by:nauman_ahmed
ID: 11827599
Hey buddy, thanks for the points.  Any other help you need, just let the people know abt it.....;)

Wish you all the best :), nauman
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Resolve Dependency Issues 4 45
Runtime Error 2 28
ASP.NET 5 Templates 2 65
Gridview alignment 1 8
After several hours of googling I could not gather any information on this topic. There are several ways of controlling the USB port connected to any storage device. The best example of that is by changing the registry value of "HKEY_LOCAL_MACHINE\S…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now