ASP.NET html-less pages

E

Epetruk

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
 
S

Steve Lutz

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
 
E

Epetruk

Steve said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top