Solved

Response.Write

Posted on 2004-08-02
9
873 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
Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

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

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

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

Suggested Solutions

Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

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