Is Response.Write out of date?

I recently had a technical interview test where I did Response.Write (). I was told that it is "old fashioned" and now there are better ways to do it. The interviewer did not specify, so I really want to know what he had in mind. Does anyone have any ideas?

+4
source share
11 answers

Response.Write is great if everything on the page is sent to them. I use it when I have to use ASPX to work with files other than HTML that I generate on the fly.

Response.Write makes no sense if you use non-empty ASPX pages.

+6
source

In the aspx-inline server script tags:

<%= SomeProperty.Name %> 

In the code, which depends on the circumstances, but usually there is a better alternative, such as HtmlTextWriter, ScriptManager (for registering your scripts), a literal control, placeholder, or something else.

+4
source

There are many other ways. I avoid using Response.Write because it depends on the exact order in which things are written to the output. I would prefer to use, for example, the Literal control and assign a value to the Text property.

Usually I also try to avoid <% = (return the value here)%> inline operators, since I like the aspx page to contain only the page structure and save server-side code instructions in the code behind the file.

+3
source

Depends on your application. Remember that <% = "some line"%> in your .aspx file is still a shortcut to Response.Write ()

If you executed all your HTML code using the Response.Write () function, then yes, it may be right. But if you used it for inline code, then this is really good.

+2
source

If this method is not marked as deprecated, I will not reject it. This, of course, is not "old fashioned." But there may be times when there are better alternatives, as they are more convenient to maintain.

For example, you might consider writing <%= %> operators in your HTML booklet, but this was introduced at the same time as HttpResponse.Write, so if one of them is "old-fashioned", both of them.

You might also want to consider using the template engine in other cases. It all depends.

If your interviewer did not want to specify, this also speaks of the interviewer.

+2
source

An ASP.Net page is a highly structured software that consists of a hierarchy of controls that are responsible for providing your own output. Inside this mode, Response.Write seems deprecated because it goes back to the original ASP pages, where everything was done inline.

Modern pages simply update the properties of controls that display their own output. Response.Write breaks the hierarchy, interrupting the control output stream.

+2
source

I don’t think that “old-fashioned” is the right term that the interviewer really wanted to say. Depending on the context, more efficient methods may be used. If you use built-in script tags, such as Jason's example, then the agreement <%= may be better suited to the task. However, if you execute any logic like <% if (*conditional*) { ... } %> , your alternatives may be limited.

0
source

It depends entirely on what you used Response.Write for.

If you were to output a string to be displayed on the page, then perhaps you should put Literal on the page, and then set the text of this literal, and not execute Response.Write.

0
source

There are probably certain circumstances in which you need Response.Write.

Suppose you store images in a database and want to transfer them through an array of bytes to your page. I do not think you can do this without Response.Write.

0
source

We have some old code in which all the HTML output was created in a VB DLL, because at that time it was the fastest way to create HTML with distributed transaction control.

However, ASP.NET canceled the need for this because it compiled the aspx files and code for the DLL for you.

Response.Write is still suitable for specific tasks, but the vast majority of encodings no longer need it.

0
source

Just in the dark, but did you suggest using Response.write for debugging? Sort of:

 Response.Write("Inside first loop."); 

If so, I would say that it is deprecated given the new debugging tools in Visual Studio / .NET.

0
source

All Articles