?
Solved

Response.Write

Posted on 2004-08-02
9
Medium Priority
?
897 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
  • 2
  • +1
9 Comments
 
LVL 4

Author Comment

by:eeyore7250
ID: 11691444
BTW: Im doing this in the Page_Load event.
0
 
LVL 14

Expert Comment

by:Ramuncikas
ID: 11691634
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
ID: 11691915
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 7

Expert Comment

by:mdamico
ID: 11694250
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
 
LVL 4

Author Comment

by:eeyore7250
ID: 11699372
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
ID: 11699542
eeyore:

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

Author Comment

by:eeyore7250
ID: 11699578
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
ID: 11700631
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 200 total points
ID: 11700750
<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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses
Course of the Month10 days, 15 hours left to enroll

770 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