J
John Rivers
hi, here is how to do it and restore sanity to aspx html rendering:
(please only reply with sensible architectural discussion - juan)
put this at the end of an aspx file (or use an include at the end
if you want to reuse it on many aspx pages)
(notice closing brace)
(start)
<%}
//Don"t change this bit
private System.Web.UI.HtmlTextWriter __output;
private System.Web.UI.Control parameterContainer;
void InitLib(System.Web.UI.HtmlTextWriter o, System.Web.UI.Control pc)
{
__output = o;
parameterContainer = pc;
}
//Convenience methods go here
string HTML(string data) {
return HttpUtility.HtmlEncode(data);
}
string URL(string data) {
return HttpUtility.UrlEncode(data);
}
string QPX(string name, string val) {
return URL(name) + "=" + URL(val) + "&";
}
//Add your rendering methods here!
void RenderLink(string Title, string URL) {
%><a href="<%=HTML(URL)%>"><%=HTML(Title)%></a><%
}
public class RenderClass {
private System.Web.UI.HtmlTextWriter __output;
private System.Web.UI.Control parameterContainer;
public RenderClass(System.Web.UI.HtmlTextWriter o,
System.Web.UI.Control p) {
__output = o;
parameterContainer = p;
}
public void Render() {
%>THIS IS RENDER CLASS FUNCTIONING!<%
}
}
//Don"t change anything after this
void ButtPlug() {
//this is the end
%>
(end)
now you can call these methods and use these classes from your aspx
page as follows:
<%
InitLib(__output, parameterContainer);
RenderClass c = new RenderClass(__output, parameterContainer);
c.Render();
%>
that means thanks to me we can now use the full power of
object oriented programming to develop user interfaces
whilst still benefiting from:
- code coloring
- code completion
- rewrite and retest without slow re-initialise of iis
- complex dhtml/javascript work is now realistic again
- class inheritance, delegates, callbacks, etc:
this also proves that microsoft deliberately made
the decision to disallow <%%> in methods and classes
BUT WHY??????????????????????????????????????????????
IT MAKES NO SENSE!!!
if you want to give people things like user controls
and custom controls
just let them do what i just did and implement an interface
or two, or derive their rendering class from another
this is simple stuff, microsoft, why did you bugger it?
HA HA HA microsoft muppets, they write some brilliant code at times
but sometimes they run with a bad idea for way to long ...
there is a concept in systems architecture i call "spirals"
an api which is well conceived has a "positive spiral"
that is that everything related to it succeeds
and it generates more and more "good stuff"
just like a foundation of a house
big chunks of asp.net are ill-conceived and result
in a "negative spiral" which means that code/apps built
on these parts of asp.net will always be faced with
problems, because they are built on a problematic concept
just by reading through 100 articles in this website
you can see the proof of this
i am not talking about beginners problems, i am talking
about people with experience (but not enough experience
to not use this features) struggling to complete very
simple tasks with broken tools
most of asp.net is very good
but aspx, html controls, user controls, custom controls,
viewstate, databinding, the page event model
really suck badly - and whoever brought them
into this world should find a new job
at least it gives an opportunity for me to solve these
issues with a product and make money
when something pisses you have to stop and think
"there is money to made, simply find a solution and sell it!"
--
on another note, i have read much nonsense about seperating
html from code
there is no seperation required
ASP IS THE PRESENTATION LAYER
most the power of asp comes from USING CODE TO EMIT HTML
so to talk about splitting rendering logic from rendering literals
is an absolute nonsense
also how can this be a sensible claim:
void Render() {
Response.Write("<html/>");
}
is acceptable, even better than:
void Render() {
%><html/><%
}
given the above list of benefits to be gained
by using code blocks given above?
please don't reply unless you understand what
i am saying and have something constructive to add
have a good day
(please only reply with sensible architectural discussion - juan)
put this at the end of an aspx file (or use an include at the end
if you want to reuse it on many aspx pages)
(notice closing brace)
(start)
<%}
//Don"t change this bit
private System.Web.UI.HtmlTextWriter __output;
private System.Web.UI.Control parameterContainer;
void InitLib(System.Web.UI.HtmlTextWriter o, System.Web.UI.Control pc)
{
__output = o;
parameterContainer = pc;
}
//Convenience methods go here
string HTML(string data) {
return HttpUtility.HtmlEncode(data);
}
string URL(string data) {
return HttpUtility.UrlEncode(data);
}
string QPX(string name, string val) {
return URL(name) + "=" + URL(val) + "&";
}
//Add your rendering methods here!
void RenderLink(string Title, string URL) {
%><a href="<%=HTML(URL)%>"><%=HTML(Title)%></a><%
}
public class RenderClass {
private System.Web.UI.HtmlTextWriter __output;
private System.Web.UI.Control parameterContainer;
public RenderClass(System.Web.UI.HtmlTextWriter o,
System.Web.UI.Control p) {
__output = o;
parameterContainer = p;
}
public void Render() {
%>THIS IS RENDER CLASS FUNCTIONING!<%
}
}
//Don"t change anything after this
void ButtPlug() {
//this is the end
%>
(end)
now you can call these methods and use these classes from your aspx
page as follows:
<%
InitLib(__output, parameterContainer);
RenderClass c = new RenderClass(__output, parameterContainer);
c.Render();
%>
that means thanks to me we can now use the full power of
object oriented programming to develop user interfaces
whilst still benefiting from:
- code coloring
- code completion
- rewrite and retest without slow re-initialise of iis
- complex dhtml/javascript work is now realistic again
- class inheritance, delegates, callbacks, etc:
this also proves that microsoft deliberately made
the decision to disallow <%%> in methods and classes
BUT WHY??????????????????????????????????????????????
IT MAKES NO SENSE!!!
if you want to give people things like user controls
and custom controls
just let them do what i just did and implement an interface
or two, or derive their rendering class from another
this is simple stuff, microsoft, why did you bugger it?
HA HA HA microsoft muppets, they write some brilliant code at times
but sometimes they run with a bad idea for way to long ...
there is a concept in systems architecture i call "spirals"
an api which is well conceived has a "positive spiral"
that is that everything related to it succeeds
and it generates more and more "good stuff"
just like a foundation of a house
big chunks of asp.net are ill-conceived and result
in a "negative spiral" which means that code/apps built
on these parts of asp.net will always be faced with
problems, because they are built on a problematic concept
just by reading through 100 articles in this website
you can see the proof of this
i am not talking about beginners problems, i am talking
about people with experience (but not enough experience
to not use this features) struggling to complete very
simple tasks with broken tools
most of asp.net is very good
but aspx, html controls, user controls, custom controls,
viewstate, databinding, the page event model
really suck badly - and whoever brought them
into this world should find a new job
at least it gives an opportunity for me to solve these
issues with a product and make money
when something pisses you have to stop and think
"there is money to made, simply find a solution and sell it!"
--
on another note, i have read much nonsense about seperating
html from code
there is no seperation required
ASP IS THE PRESENTATION LAYER
most the power of asp comes from USING CODE TO EMIT HTML
so to talk about splitting rendering logic from rendering literals
is an absolute nonsense
also how can this be a sensible claim:
void Render() {
Response.Write("<html/>");
}
is acceptable, even better than:
void Render() {
%><html/><%
}
given the above list of benefits to be gained
by using code blocks given above?
please don't reply unless you understand what
i am saying and have something constructive to add
have a good day