Solved

Response.Write

Posted on 2004-08-02
9
852 Views
Last Modified: 2012-06-27
I’m using Response.Write to insert HTML into my pages. Unfortunately it adds the code to the beginning of the file. I won’t to be able to specify the position of where I want the html inserted, so it goes into the HTML block. I’m wondering if I'm using the right class and method or whether there is a newer more friendly class and method that work similarly to the Page.RegisterStartupScript?
0
Comment
Question by:eeyore7250
  • 4
  • 2
  • 2
  • +1
9 Comments
 
LVL 4

Author Comment

by:eeyore7250
Comment Utility
BTW: Im doing this in the Page_Load event.
0
 
LVL 14

Expert Comment

by:Ramuncikas
Comment Utility
If you know the place where the text should appear I sugest using label controls.
For exapmle many sites have dates in particular places of their sites. The code should look like this (page_load event):

Label1.Text=Date.Today.ToShortString

Hope this helps.
Good luck
0
 
LVL 9

Expert Comment

by:crescendo
Comment Utility
Put Response.Write in your HTML, enclosed in script tags, "<%" and "%>" if you must. This is very archaic, the "modern" way to output HTML is to add controls dynamically. You can insert an ASP:Placeholder to specify where they are inserted.

Using a label will work too, and you can put as much HTML as you want into it, it will get rendered as if you had put HTML straight into your page. For example, if you do

    Label1.Text = "Line 1" + "<br>" + "Line 2"

the output will appear on two lines. You can extend the concept to include other HTML tags.
0
 
LVL 7

Expert Comment

by:mdamico
Comment Utility
My first thought would be to use a placeholder.

<asp:Placeholder id="place1" runat="server" />


In code behind:

place1.Controls.Add(New LiteralControl("Whatever HTML you want<br>"))
place1.Controls.Add(New LiteralControl("<b>Some more HTML</b><br>"))
0
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
LVL 4

Author Comment

by:eeyore7250
Comment Utility
Yes you are right, what I am doing is archaic... however, Microsoft have failed to implement some very archaic principles. Like for example, server controls only seem to POST actions, when what most of the time they should be doing is the GET action. It is for this reason, that with this version of ASP.Net I want to avoid using server controls.

Place holders seem to be the way to go and if I receive no more comments I will award the points to mdamico for their clear and concise comment and example.
0
 
LVL 9

Expert Comment

by:crescendo
Comment Utility
eeyore:

Can I just point out that I suggested a placeholder first?
0
 
LVL 4

Author Comment

by:eeyore7250
Comment Utility
You can do all you like mate...

I've already outlined my reasons for my preferred comment thus far.
0
 
LVL 4

Author Comment

by:eeyore7250
Comment Utility
Ok, place holders sort of answer my question. However, not fully.

It seems you can only use place holders in the body of a page. This is not sufficient for when header information needs to be dynamic. I.E. The title tag and meta tags.

I am therefore leaving this question, pending more comments.
0
 
LVL 7

Accepted Solution

by:
mdamico earned 50 total points
Comment Utility
<HTML>
      <HEAD id="head1" runat="server">
            <title runat="server" id="pagetitle"></title>
      </HEAD>
      <body>
            <form id="Form1" method="post" runat="server">
            </form>
      </body>
</HTML>


In codebehind:

  Protected pagetitle As HtmlGenericControl
  Protected head1 As HtmlContainerControl

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    pagetitle.InnerText = "My page Title"
    head1.Controls.Add(New LiteralControl("<meta name='GENERATOR' content='Microsoft Visual Studio .NET 7.1'>" & System.Environment.NewLine))
    head1.Controls.Add(New LiteralControl("<meta name='CODE_LANGUAGE' content='Visual Basic .NET 7.1'>" & System.Environment.NewLine))
    head1.Controls.Add(New LiteralControl("<meta name='vs_defaultClientScript' content='JavaScript'>" & System.Environment.NewLine))
    head1.Controls.Add(New LiteralControl("<meta name='vs_targetSchema' content='http://schemas.microsoft.com/intellisense/ie5'>" & System.Environment.NewLine))
    End Sub
0

Featured Post

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

Join & Write a Comment

One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

763 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

13 Experts available now in Live!

Get 1:1 Help Now