Light ASP.Net Page

  • Thread starter Thread starter Thalia Mei
  • Start date Start date
T

Thalia Mei

Hi,

Would like to know what is the best way of creating an ASP.Net web page that
return just a line of "Text".

This ASP.Net will not required any HTML tag, or Post Back Features.

So we created below in Code Behind:

protected override void Render(HtmlTextWriter writer)
{
base.Render(writer);
Response.Clear();
Response.ContentType = "text/plain";

// Some Business Logic

Response.Write(sometext)
}

Is this the best way? The return result "sometext" will be used by
javascript (Ajax). But we still have this in our Form Code:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Test.aspx.cs"
Inherits="CUST_Test._Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div></div>
</form>
</body>
</html>

Shall i remove all above from the Form Code?

Instead of protected override void Render(HtmlTextWriter writer), can we
just do something like this (probably in the Form Code):

<%
Response.Clear();
Response.ContentType = "text/plain";

// Some Business Logic

Response.Write(sometext)
%>

and then remove all Code Behind and everything, will that improve
performance?

Really appreciate if you can help. Millions Thanks!
 
You could just remove everything and place a Literal control on the page. A
literal doesn't get decorated with extra <span> elements like a Label does.
Your way also works but in either case you'll need to do things like turn
off the session state to ensure it doesn't try to write a viewstate as well.

Hope this helps,
Mark Fitzpatrick
Microsoft MVP - Expression
 
You have a couple of questions, so let's examine them

The lightest you can go is to just spit out the text. Response.Write()
works, as does using a Literal (Mark's suggestion). If you do this, you
should remove all HTML tags, as they will be written if they are on the
page.

Removing CodeBehind? WIll not improve performance. Will make it, depending
on publish mode, so you can alter this single page without updating the
entire site. If that is not a desire, then you really gain nothing by
removing CodeBehind, as you can completely clear out the page and use
CodeBehind only to do what you are trying to do.

One question I have is why you are using a page to deliver text to an AJAX
page? There are so many better ways to accomplish this, including web
services.

--
Gregory A. Beamer
MVP, MCP: +I, SE, SD, DBA

Subscribe to my blog
http://gregorybeamer.spaces.live.com/lists/feed.rss

or just read it:
http://gregorybeamer.spaces.live.com/

*************************************************
| Think outside the box!
|
*************************************************
 
Hi,

Thanks everyone for advice.

The reason we are not using web services is because we try to minimize the
size of the return message, as web services will include extra tags.

The message we return is just one liner that retrieve from a stored
procedure.

I am not sure whether web services is advisable?

Thanks
 
Back
Top