Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Simple ASP.NET Output Question

Simple ASP.NET Output Question

Scheduled Pinned Locked Moved ASP.NET
csharpquestionhtmlasp-nethelp
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    tantiboh
    wrote on last edited by
    #1

    Although competent in C#, I'm new at ASP.NET, so this one's got me stumped. I've build a basic aspx page, and I want to write HTML lines to it programmatically through the Page_Load event handler. Here's the code: private void Page_Load(object sender, System.EventArgs e) { SqlCommand cmFAQs = new SqlCommand("SELECT Question, Answer FROM tblWebFAQsQuestion", this.cnFAQs); this.cnFAQs.Open(); SqlDataReader rdrFAQs = cmFAQs.ExecuteReader(CommandBehavior.CloseConnection); int i = 0; while (rdrFAQs.Read()) { this.Page.Response.Output.WriteLine(" "); this.Page.Response.Output.WriteLine(rdrFAQs.GetString(0)); this.Page.Response.Output.WriteLine(" "); this.Page.Response.Output.WriteLine(" "); this.Page.Response.Output.WriteLine("**Answer:** "); this.Page.Response.Output.WriteLine(rdrFAQs.GetString(1)); this.Page.Response.Output.WriteLine(" "); i++; } rdrFAQs.Close(); } It works great, except one thing - which will be obvious to any veteran. The WriteLine method outputs the line to the beginning of the HTML page. I need the output to be placed inside the of the page so I can build a form around it. Is there a (hopefully simple) way to do this? Thanks for your help!

    G 1 Reply Last reply
    0
    • T tantiboh

      Although competent in C#, I'm new at ASP.NET, so this one's got me stumped. I've build a basic aspx page, and I want to write HTML lines to it programmatically through the Page_Load event handler. Here's the code: private void Page_Load(object sender, System.EventArgs e) { SqlCommand cmFAQs = new SqlCommand("SELECT Question, Answer FROM tblWebFAQsQuestion", this.cnFAQs); this.cnFAQs.Open(); SqlDataReader rdrFAQs = cmFAQs.ExecuteReader(CommandBehavior.CloseConnection); int i = 0; while (rdrFAQs.Read()) { this.Page.Response.Output.WriteLine(" "); this.Page.Response.Output.WriteLine(rdrFAQs.GetString(0)); this.Page.Response.Output.WriteLine(" "); this.Page.Response.Output.WriteLine(" "); this.Page.Response.Output.WriteLine("**Answer:** "); this.Page.Response.Output.WriteLine(rdrFAQs.GetString(1)); this.Page.Response.Output.WriteLine(" "); i++; } rdrFAQs.Close(); } It works great, except one thing - which will be obvious to any veteran. The WriteLine method outputs the line to the beginning of the HTML page. I need the output to be placed inside the of the page so I can build a form around it. Is there a (hopefully simple) way to do this? Thanks for your help!

      G Offline
      G Offline
      Guffa
      wrote on last edited by
      #2

      Put the html code in a string (use a StringBuilder) and put the string in the InnerHtml property of a place holder (a div tag with runat="server") on the page. Use quotes instead of apostrophes in the html code. --- b { font-weight: normal; }

      T 1 Reply Last reply
      0
      • G Guffa

        Put the html code in a string (use a StringBuilder) and put the string in the InnerHtml property of a place holder (a div tag with runat="server") on the page. Use quotes instead of apostrophes in the html code. --- b { font-weight: normal; }

        T Offline
        T Offline
        tantiboh
        wrote on last edited by
        #3

        Of course! Thanks.

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups