469,616 Members | 1,806 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,616 developers. It's quick & easy.

ASP.NET html-less pages

Hi,

I'm looking for samples of ASP.NET projects where the programming has been
done almost entirely using codebehind and classes with very little code in
the aspx files themselves.

I would like to be able to write ASP.NET pages where I represented the
elements on the page entirely with classes in codebehind (let's call them
RenderClasses). The idea would be that each of these classes would have a
Render method which would cause the appropriate html to be generated on
screen when it was called so that the visual element that the class instance
represented would be displayed in the browser.

So when the page loaded (in Page_Load), I would instantiate different types
of these RenderClasses, set their various properties and then I would call
their Render methods. Also, if I needed to change the appearance of the page
after user interaction, I would simply change the properties of these
instances in codebehind and then call the Render method. (Something like the
model-view-controller architecture.)

I know that the ASP.NET model has classes that derive from
System.Web.UI.Control that represent many of the common elements we have in
forms. Would these classes do exactly what I want? Would it be possible for
me to have an aspx page which had no html at all, with the html being
generated by the Render methods? And very importantly, does anyone know of
any sample project that has been written using this technique? Are there any
potential pitfalls in terms of server processing?

Thanks in advance,

--
Akin

aknak at aksoto dot idps dot co dot uk

of these classes that would cause appropriate content to be displayed on
the browser. Also, if I needed to change the appearance of the page through
user interaction, I would change the properties of the class instances then
call the Render method
Nov 19 '05 #1
3 1330
Akin,

If you leave the ASPX page empty (no HTML), you can just use Response.Write
to output HTML.

Custom controls can use HTTPCurrentContext to output also when their Rended
method is invoked.

So you're Page_Load might look like:

.... C# ....
MyCustomerControl mc1 = new MyCustomControl1();
mc1.SomeProperty = somevalue;
mc1.Render();
..........

There is also alot of alternatives you could do with this:
Instead of manually calling the control's Render method, you could add it as
a delegate for your Page's onRender event. I believe this is how it's done
when you use the standard WebControls.

I have a question on why you would want this? Is this to obscure the output?

Steve

"Epetruk" <no****@blackhole.com> wrote in message
news:36*************@individual.net...
Hi,

I'm looking for samples of ASP.NET projects where the programming has been
done almost entirely using codebehind and classes with very little code in
the aspx files themselves.

I would like to be able to write ASP.NET pages where I represented the
elements on the page entirely with classes in codebehind (let's call them
RenderClasses). The idea would be that each of these classes would have a
Render method which would cause the appropriate html to be generated on
screen when it was called so that the visual element that the class instance represented would be displayed in the browser.

So when the page loaded (in Page_Load), I would instantiate different types of these RenderClasses, set their various properties and then I would call
their Render methods. Also, if I needed to change the appearance of the page after user interaction, I would simply change the properties of these
instances in codebehind and then call the Render method. (Something like the model-view-controller architecture.)

I know that the ASP.NET model has classes that derive from
System.Web.UI.Control that represent many of the common elements we have in forms. Would these classes do exactly what I want? Would it be possible for me to have an aspx page which had no html at all, with the html being
generated by the Render methods? And very importantly, does anyone know of
any sample project that has been written using this technique? Are there any potential pitfalls in terms of server processing?

Thanks in advance,

--
Akin

aknak at aksoto dot idps dot co dot uk

of these classes that would cause appropriate content to be displayed on
the browser. Also, if I needed to change the appearance of the page through user interaction, I would change the properties of the class instances then call the Render method

Nov 19 '05 #2
Check out the HtmlTextWriter.AddAttribute(), .AddStyleAttribute(),
..RenderBeginTag() and .RenderEndTag() methods and the HtmlTextWriterTag and
HtmlTextWriterAttribute enumerations on MSDN. They're great for creating
HTML in code.

If you really want to get into the nuts and bolts, check out the
IHttpHandler interface starting at
http://msdn.microsoft.com/library/de...tphandlers.asp.

HTH

DalePres
MCAD, MCDBA, MCSE

"Steve Lutz" <sl***@nospam.comcast.net> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl...
Akin,

If you leave the ASPX page empty (no HTML), you can just use
Response.Write
to output HTML.

Custom controls can use HTTPCurrentContext to output also when their
Rended
method is invoked.

So you're Page_Load might look like:

.... C# ....
MyCustomerControl mc1 = new MyCustomControl1();
mc1.SomeProperty = somevalue;
mc1.Render();
..........

There is also alot of alternatives you could do with this:
Instead of manually calling the control's Render method, you could add it
as
a delegate for your Page's onRender event. I believe this is how it's done
when you use the standard WebControls.

I have a question on why you would want this? Is this to obscure the
output?

Steve

"Epetruk" <no****@blackhole.com> wrote in message
news:36*************@individual.net...
Hi,

I'm looking for samples of ASP.NET projects where the programming has
been
done almost entirely using codebehind and classes with very little code
in
the aspx files themselves.

I would like to be able to write ASP.NET pages where I represented the
elements on the page entirely with classes in codebehind (let's call them
RenderClasses). The idea would be that each of these classes would have a
Render method which would cause the appropriate html to be generated on
screen when it was called so that the visual element that the class

instance
represented would be displayed in the browser.

So when the page loaded (in Page_Load), I would instantiate different

types
of these RenderClasses, set their various properties and then I would
call
their Render methods. Also, if I needed to change the appearance of the

page
after user interaction, I would simply change the properties of these
instances in codebehind and then call the Render method. (Something like

the
model-view-controller architecture.)

I know that the ASP.NET model has classes that derive from
System.Web.UI.Control that represent many of the common elements we have

in
forms. Would these classes do exactly what I want? Would it be possible

for
me to have an aspx page which had no html at all, with the html being
generated by the Render methods? And very importantly, does anyone know
of
any sample project that has been written using this technique? Are there

any
potential pitfalls in terms of server processing?

Thanks in advance,

--
Akin

aknak at aksoto dot idps dot co dot uk

of these classes that would cause appropriate content to be displayed on
the browser. Also, if I needed to change the appearance of the page

through
user interaction, I would change the properties of the class instances

then
call the Render method


Nov 19 '05 #3
Steve Lutz wrote:
Akin,

If you leave the ASPX page empty (no HTML), you can just use
Response.Write to output HTML.

Custom controls can use HTTPCurrentContext to output also when their
Rended method is invoked.

So you're Page_Load might look like:

.... C# ....
MyCustomerControl mc1 = new MyCustomControl1();
mc1.SomeProperty = somevalue;
mc1.Render();
..........

There is also alot of alternatives you could do with this:
Instead of manually calling the control's Render method, you could
add it as a delegate for your Page's onRender event. I believe this
is how it's done when you use the standard WebControls.

I have a question on why you would want this? Is this to obscure the
output?


Hi Steve,

Thanks for your answer.

To answer your question about why I would want to do this: well, coming from
a desktop software development background, I guess I'm more comfortable with
a model where the UI is entirely represented in a programming language like
VB or C#.

Cheers,

Akin
Nov 19 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by cirillo_curiosone | last post: by
9 posts views Thread by Patient Guy | last post: by
reply views Thread by devrayhaan | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.