ASP.NET html-less pages

Discussion in 'ASP .Net Web Controls' started by Epetruk, Feb 8, 2005.

  1. Epetruk

    Epetruk Guest

    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
    Epetruk, Feb 8, 2005
    #1
    1. Advertising

  2. Epetruk

    DalePres Guest

    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/d...us/cpguide/html/cpconcreatinghttphandlers.asp.

    HTH

    DalePres
    MCAD, MCDBA, MCSE

    "Steve Lutz" <> wrote in message
    news:%...
    > 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" <> wrote in message
    > news:...
    >> 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
    >>
    >>

    >
    >
    DalePres, Feb 8, 2005
    #2
    1. Advertising

  3. Epetruk

    Epetruk Guest

    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
    Epetruk, Feb 8, 2005
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Manish
    Replies:
    1
    Views:
    632
    Steve C. Orr [MVP, MCSD]
    Nov 17, 2003
  2. Epetruk

    ASP.NET html-less pages

    Epetruk, Feb 8, 2005, in forum: ASP .Net
    Replies:
    3
    Views:
    1,394
    Epetruk
    Feb 8, 2005
  3. jiajia wu
    Replies:
    0
    Views:
    345
    jiajia wu
    Oct 1, 2009
  4. 6668
    Replies:
    0
    Views:
    141
  5. lllll
    Replies:
    0
    Views:
    121
    lllll
    Jun 8, 2009
Loading...

Share This Page