Link to home
Start Free TrialLog in
Avatar of the_sleeper
the_sleeperFlag for United States of America

asked on

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

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
Avatar of nauman_ahmed
nauman_ahmed
Flag of United States of America image

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
Avatar of the_sleeper

ASKER

@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
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
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
@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?
 
SOLUTION
Avatar of nauman_ahmed
nauman_ahmed
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Just copy and paste the HelloWorld.aspx code in the NotePad and save your file.

-Nauman
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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.


Thanks to everyone who responded. I'll try harder!
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!
Avatar of shovavnik
shovavnik

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!
Hey buddy, thanks for the points.  Any other help you need, just let the people know abt it.....;)

Wish you all the best :), nauman