Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   ASP .Net (http://www.velocityreviews.com/forums/f29-asp-net.html)
-   -   asp.net equivalent of <% response.write("") %> (http://www.velocityreviews.com/forums/t120230-asp-net-equivalent-of-response-write.html)

samuelberthelot@googlemail.com 02-23-2006 04:06 PM

asp.net equivalent of <% response.write("") %>
 
Hi,
I have the following in my asp page:

<% response.write(Header) %>

where Header contains HTML markup such ass <html> <body> ....

I must write the code in the aspx file and not in the code behind so
that the markup are generated at correct places in html stream.

I've tried :

<script runat=server>
response.write(Header)
</script>

but that wouldn't work. How can i do it ?

Thank you.


Hugo Flores 02-23-2006 04:48 PM

Re: asp.net equivalent of <% response.write("") %>
 
You should be able to do it in the same way as you do it now with <%
response.write(Header) %>.
The script section you tried should also work, even though I've never
used it myself as I always use the <% %>, if I have to code something
in the aspx file.
So maybe the problem is that you are not getting the Header right,
where are you getting the Header from?


samuelberthelot@googlemail.com 02-23-2006 05:22 PM

Re: asp.net equivalent of <% response.write("") %>
 
Yes I know I can do it with <% %> and it works fine actually.
But I was told this is not good to do this in asp.net anymore.
I should use the <script> markup but if I do then it wouldn't work for
some reason. :(


Hugo Flores 02-28-2006 09:08 PM

Re: asp.net equivalent of <% response.write("") %>
 
It's not good to do that in .net anymore????
Who told you that?
It's the same thing as doing it on the script block.


samuelberthelot@googlemail.com 03-01-2006 09:19 AM

Re: asp.net equivalent of <% response.write("") %>
 
I've read that in a book that using <% %> in the aspx page instead of
<script/> is not good. It is obsolete...


Hugo Flores 03-01-2006 04:02 PM

Re: asp.net equivalent of <% response.write("") %>
 
I never heard that before, but well if you don't want to use <% %>
which works, then I think that you would have to use a control that
parses the html and place it exactly where you want the html to be
placed (if that's even possible, because I never had to do this).
Because it seems that if you want to use the script block, the Response
object, or any other for that matter need to be written under any
method or property.
I think, if it fits your need you should go with what works for your
solution, no matter how "obsolete" it is. And if it's obsolete how come
directives still use the <% %>.
Notice that I'm not encouraging the use of <% %> in any way. But in
your particular case, that's the best way to go. In any other case,
where you just want to write something into a page, is better to use
controls and place it under their corresponding property.

HTH


Christopher Reed 03-02-2006 01:11 PM

Re: asp.net equivalent of <% response.write("") %>
 
You should avoid the <% %> construct any more because it doesn't conform
with the ASP.NET programming model. There are instances within controls
like Repeater and DataList where it is appropriate to use <%# %> when you're
trying to add database table values to a control. But to use the <%= %>
construct that is from classic ASP is no longer appropriate with the new
programming model. Look at the MSDN documentation for more information.
--
Christopher A. Reed
"The oxen are slow, but the earth is patient."

<samuelberthelot@googlemail.com> wrote in message
news:1140710806.935889.226220@z34g2000cwc.googlegr oups.com...
> Hi,
> I have the following in my asp page:
>
> <% response.write(Header) %>
>
> where Header contains HTML markup such ass <html> <body> ....
>
> I must write the code in the aspx file and not in the code behind so
> that the markup are generated at correct places in html stream.
>
> I've tried :
>
> <script runat=server>
> response.write(Header)
> </script>
>
> but that wouldn't work. How can i do it ?
>
> Thank you.
>




Alan Silver 03-02-2006 04:43 PM

Re: asp.net equivalent of <% response.write("") %>
 
><samuelberthelot@googlemail.com> wrote in message
>news:1140710806.935889.226220@z34g2000cwc.googleg roups.com...
>> Hi,
>> I have the following in my asp page:
>>
>> <% response.write(Header) %>
>>
>> where Header contains HTML markup such ass <html> <body> ....


We discussed this already in another thread. It was pointed out to you
that this isn't a good idea. You shouldn't store the HTML in the
database, rather store the attributes (eg page title, meta description,
etc) in the database and populate server controls.

>> I must write the code in the aspx file and not in the code behind so
>> that the markup are generated at correct places in html stream.


That doesn't make sense. Populating in the aspx file does not give you
any more control over where the HTML is generated, and it mixes code
with presentation. Code-behind gives you full control over where the
HTML (or any other content) is placed.

You are thinking in a classic ASP way, and that is hindering your
attempts.

Furthermore, as already explained, this will *not* allow you to mark the
HTML you're writing as runat="server" anyway, so your attempts to use
themes with such a header will simply not work, no matter how many times
you ask the question.

>> I've tried :
>>
>> <script runat=server>
>> response.write(Header)
>> </script>
>>
>> but that wouldn't work. How can i do it ?


You could read the suggestions you've already been given. What you show
above will definitely work, it will insert the HTML at the specified
place. However, having a Literal control in the aspx file and setting
its Text property in the code-behind works just as well, but has major
advantages of separating the code from the presentation.

For example, if your HTML in the aspx file looks like this...

<head runat="server">
<title><asp:Literal id=litTitle" runat="server" /></title>
</head>

then you can set the title of the page from code-behind *and* have
themes working.

--
Alan Silver
(anything added below this line is nothing to do with me)


All times are GMT. The time now is 10:56 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.