positioning the output of response.write in asp.net C#

℡╲_俬逩灬. 提交于 2019-12-25 09:31:17

问题


i am trying to postion the output to my aspx page by using response.write for that i am using this code:

Response.Write("&lt;<span id='Label1'' style='height:16px;width:120px;Z-INDEX: 102; LEFT: 288px; POSITION: absolute; TOP: 144px'>Its not at the top left corner!</span>");

this prints my message in the middle of the screen but also shows a "<" at the left corner. I have tried a few things but i am unable to get rid of it.

please help

any other way of positioning the output?


回答1:


Try:

Response.Write("<span id='Label1' style='height:16px;width:120px;Z-INDEX: 102; LEFT: 288px; POSITION: absolute; TOP: 144px'>Its not at the top left corner!</span>");

You had a &lt; at the beginning, which is giving you the "<" , and a double '' after Label1

But there are LOTS of better ways of positioning with CSS and producing output with Response.Write directly is generally not needed... What are you trying to do?




回答2:


This or this or something like it will help you.




回答3:


man, i sometimes use response.write to make some quick output of HTML, but i really advise not to use it on big scale as there are much nicer and better ways to create clean HTMl output

  • there is a very nice feature called ParseControl(), which takes a string and convert it to control, like the one you did above.
  • use HTMLWriter.
  • use HTMLGeneric Control.

with all previous mentioned methods you can have nice control on a custom output you like.

Good luck.




回答4:


A more simple way instead of literals:

@Html.Raw("<h1>text</h1>");


来源:https://stackoverflow.com/questions/742255/positioning-the-output-of-response-write-in-asp-net-c-sharp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!