Solved

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

Posted on 2004-08-17
13
292 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
Comment Utility
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
Comment Utility
@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
Comment Utility
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
Comment Utility
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
Comment Utility
@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
Comment Utility
Yes. You got it right buddy :)

-Nauman
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 25

Expert Comment

by:nauman_ahmed
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Thanks to everyone who responded. I'll try harder!
0
 

Author Comment

by:the_sleeper
Comment Utility
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
Comment Utility
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
Comment Utility
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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

What my article will show is if you ever had to do processing to a listbox without being able to just select all the items in it. My software Visual Studio 2008 crystal report v11 My issue was I wanted to add crystal report to a form and show…
A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
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…

771 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

12 Experts available now in Live!

Get 1:1 Help Now