Solved

Response.Write

Posted on 2004-08-02
9
891 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
SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

 
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

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

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

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…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
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…

730 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