Solved

Response.Write

Posted on 2004-08-02
9
864 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
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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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 50 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

895 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

11 Experts available now in Live!

Get 1:1 Help Now