Writing HTML / Javascript into document dynamically

Last post 01-06-2006 7:08 PM by mattgi. 3 replies.

Sort Posts:

  • Writing HTML / Javascript into document dynamically

    01-06-2006, 3:07 PM
    • Member
      5 point Member
    • thedecline77
    • Member since 01-06-2006, 7:57 PM
    • Posts 1
    I have to admit that I am used to using Perl's programming structure for web pages, not ASP.  I delved into ASP.NET a few weeks ago and found a lot of the controls to be helpful and easy, but there are still times when I think the easiest way to accomplish something would be dynamically and linearly writting HTML and JS into a page like with perl.  The only way I have found to do this is by hijacking the stream which then does not allow you to fit the HTML/JS into an ASP document with other controls.  Is there any way to programmatically write client-side scripts/languages into an ASP document like into a PlaceHolder or something?  I know I probably just want the best of both worlds and can't have it, but it would be nice.
  • Re: Writing HTML / Javascript into document dynamically

    01-06-2006, 3:24 PM
    • Member
      486 point Member
    • mattgi
    • Member since 06-11-2002, 8:31 AM
    • Redmond
    • Posts 107

    The placeholder control is more typically used to add a set of server controls to the page dynamically.  If you want to write directly to the output, there are a couple of other ways to do it.  Hey, if you've been using PERL then you expect there to be more than one way.

    You could create a user control (an .ascx file) and include an override there for the Render method where you write out what you want to the output stream.  It's location on the page would be wherever you included the user controls.

    You could also do this by creating a custom control, inheriting from WebControl and override the Render method there too.

    Either of these methods allow you to override other parts of the page/control lifecycle so you get a lot of programmatic flexibility about interacting with the user input and determining the structure of what you want to write out.



    This posting is provided "AS IS" with no warranties, and confers no rights.
  • Re: Writing HTML / Javascript into document dynamically

    01-06-2006, 6:58 PM
    • Contributor
      3,045 point Contributor
    • wessamzeidan
    • Member since 03-01-2003, 2:07 AM
    • Lebanon - Palestinian
    • Posts 610
    • TrustedFriends-MVPs
    you can always use a literal control to inject whatever you want in the page.
    Wessam Zeidan
  • Re: Writing HTML / Javascript into document dynamically

    01-06-2006, 7:08 PM
    • Member
      486 point Member
    • mattgi
    • Member since 06-11-2002, 8:31 AM
    • Redmond
    • Posts 107

    Good point.  You could put an asp:literalcontrol on the page and then just override  a page method to fill it up with whatever.  You wouldn't get the encapsulation of a user control or custom control, but that may not be what you are after.



    This posting is provided "AS IS" with no warranties, and confers no rights.
Page 1 of 1 (4 items)