Positioning in Output Code

M

Martin Eyles

Hi,
I have an asp.net page, which uses the response.write method calls
in the Page_Load method to output dynamically to the page. Unfortunately,
this always inserts text at the beginning of the file, before the
<!DOCTYPE...> definition. I would like to control the position, so that it
always appears in a certain place in my code (within a div or span with a
defined id). I did consider using innerHTML, but this doesn't appear to work
at all, getting compiler errors. Does anyone have any other ideas?

Thanks,
Martin

--
Martin Eyles
(e-mail address removed)


_______CODE BELOW________

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
Response.Write("TEST")
End Sub

_________Gives__________

TEST <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0
Transitional//EN"> <html>
<head>
<title>TEST</title>
<meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" content="Visual Basic .NET 7.1">
<meta name=vs_defaultClientScript content="JavaScript">
<meta name=vs_targetSchema
content="http://schemas.microsoft.com/intellisense/ie5">
</head>
<body MS_POSITIONING="GridLayout">

<form name="Form1" method="post" action="TEST.aspx" id="Form1">
<input type="hidden" name="__VIEWSTATE"
value="dDwtNjU0MzcyMTk1Ozs+iI5lAOcC76OEBXsnSYfQpECsHAI=" />


</form>

</body>
</html>
 
G

Guest

Add an appropriate asp.net control (e.g. a label) and write to it from within
the Page_Load routine.

e.g.

<asp:Label id="Label1" runat="server">Label</asp:Label>

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs)
Label1.Text = "Some text"
End Sub

HTH

Alan
 
H

Hans Kesting

Martin said:
Hi,
I have an asp.net page, which uses the response.write method
calls in the Page_Load method to output dynamically to the page.
Unfortunately, this always inserts text at the beginning of the file,
before the <!DOCTYPE...> definition. I would like to control the
position, so that it always appears in a certain place in my code
(within a div or span with a defined id). I did consider using
innerHTML, but this doesn't appear to work at all, getting compiler
errors. Does anyone have any other ideas?

Thanks,
Martin

Various options:
* use a <asp:Label> to output plain text (no html)
* use a <div> (or <span>) with an id argument *and* a "runat=server",
then (maybe switch briefly to design mode) you can access InnerText
and InnerHtml properties. (InnerText escapes special characters, InnerHtml
preserves them)

Hans Kesting
 
K

Kevin Spencer

Response.Write writes HTML to the Response.OutputBuffer. As ASP.Net is
object-oriented ASP.Net usually handles the writing of HTML to the
Response.OutputBuffer, as it is done using UI Controls that write their own
HTML out at the approproate time. I would suggest that, rather than fighting
the model, work with it. Use the object-oriented approach that ASP.Net was
designed for. IOW, DON'T use Response.Write, unless you're writing a
spoecific type of class which would handle all its own HTML-writing.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Neither a follower
nor a lender be.
 
M

Martin Eyles

Thanks. Did a <div> tag as you suggested with

dispMachines.InnerHtml() = dispMachines.InnerHtml() + "HELLO"

in my vb code. Works a treat

Regards,
Martin
 
M

Martin Eyles

I have tried doing a similer thing with an image. There is only one copy of
the image, but it's name will come from a database, so I want to modify its
src value in my code.

In the html I have:-
<img id="lineGraphic" runat="server" src="" style="position:absolute;
z-index:0" />

And in the Page_Load method I have:-
lineGraphic.src() = "graphics/sd02main.png"

unfortunately, I get the error "Name 'lineGraphic' is not declared." in the
Task List, and the vb code does not recompile. How can I fix this?

Thanks,
Martin
 
M

Martin Eyles

Very Strange. I just looked at the web form in Design view, and that fixed
the error in the completely seperate vb file. It also (rather anoyingly)
capitalized my html tags (<html> became <HTML>). Not sure if these are bugs
or "features". Any ideas what is causing this?

Thanks,
Martin
 
H

Hans Kesting

Martin said:
Very Strange. I just looked at the web form in Design view, and that
fixed the error in the completely seperate vb file. It also (rather
anoyingly) capitalized my html tags (<html> became <HTML>). Not sure
if these are bugs or "features". Any ideas what is causing this?

Thanks,
Martin

See my earlier (cryptic) comment about switching to design mode..
The fact that you edit the html (in aspx/ascx) does not declare that
control in the codebehind file. When you switch to design-mode,
VS.Net notices some declarations are missing and adds them.

Capitalizing some tags and changing the layout of the html seems
to be considered more of a "bug", or an undesired feature.


Hans Kesting
 
M

Martin Eyles

Thanks,
Martin

See my earlier (cryptic) comment about switching to design mode..
The fact that you edit the html (in aspx/ascx) does not declare that
control in the codebehind file. When you switch to design-mode,
VS.Net notices some declarations are missing and adds them.

Do you mean these two lines are put in when you switch to design view?

Protected WithEvents dispMachines As
System.Web.UI.HtmlControls.HtmlGenericControl

Protected WithEvents lineGraphic As System.Web.UI.HtmlControls.HtmlImage
Capitalizing some tags and changing the layout of the html seems
to be considered more of a "bug", or an undesired feature.

Discovered something in options (Tools, Options, HTML/XML, Format,
Capitalisation) that tames the capitalisation of html. However its
equivalent for css (Tools, Options, HTML/XML, Format, Capitalisation)
appears not to work (ie. set to lowercase, and it all becomes uppercase).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,143
Latest member
DewittMill
Top