Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8052945
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T07:41:58+00:00 2026-06-05T07:41:58+00:00

More specifically, I have made a small webpage using C# and a .aspx document.

  • 0

More specifically, I have made a small webpage using C# and a .aspx document. All C# code I have put in the <head> part of my document, inside Page_Load like this:

<script language="C#" runat="server">
protected void Page_Load(Object s, EventArgs e) {  
     Response.Write(@"<div class=""header"">Foo Bar</div>");
     ...
}
</script>

This works somehow, but the problem is that the html generated by this gets stuffed on top of the beginning <html> tag in the document which results in a broken character setting (doesn’t read the meta tag?) and strange things not supposed to happen. I’m new to using ASP.NET and it’s obvious. Where would I put all my statements so that they would be reachable from the <body> using <% delimiters?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T07:42:01+00:00Added an answer on June 5, 2026 at 7:42 am

    You would put them in the body. This particular code doesn’t do anything more than write directly to the spot where you’ve put it.

    <body>
    
        <%= @"<div class=""header"">Foo Bar</div>"; %>
    
    </body>
    

    I’m sure this is just a test of something, but if you want to write to a specific place in the page you’d be better off using a label or literal control:

    <head>
    <script language="#C" runat="server">
    
        <script language="C#" runat="server">
        protected void Page_Load(Object s, EventArgs e)
        {  
             this.lblWriteToMe.Text = @"<div class=""header"">Foo Bar</div>");
             // ...
        }
    
        </script>
    </head>
    
    <body>
        <asp:Label ID="lblWriteToMe" runat="server" />
    </body>
    </html>
    

    Edit:
    In order to place text in an html block you would put that directly into the html block you want it to appear in as I did in the first sample. It’s a very “classic asp” method of doing it, though MVC is bringing the concept back. The script tag at the top can hold all of the method/event definitions and global variables/properties or whatever, but when you use Response.Write or <%= it will output it as soon as it appears. Keep in mind, that a standard webforms page has an event lifecycle that has to be considered and Response.Write can interfere with that. If you have output generated in methods or events, you would be better off posting that result into a control. This will allow the control to determine the proper order of rendering within the html block as it comes out in Page_Render.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Or at least the part of it, that makes sense. More specifically I have
I have been using telerik extensions for an asp.net mvc project, more specifically the
More specifically, does NDK have a complete STL implementation. We're looking at this for
I am learning about regular expressions and more specifically word boundries. I have a
More specifically, I was using homebrew to install MySQL, and I got this error:
When using the PHP Tidy Library (More Specifically, The tidy_repair_string function) I keep getting
More specifically, I have (simplified) the following: union foo { volatile int bits; char
More specifically, does CL require the user to have a data connection? Or is
I just learned about the i/o part of the STL, more specifically fstream. Although
More specifically: I have a sequence of 32 bit unsigned RGBA integers for pixels-

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.