CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Nov 2002
    Location
    Devon, UK
    Posts
    212

    Creating HTML to insert at run-time

    Forgive me, I'm self-teaching a move to ASP.NET from Windows forms...questions questions...

    I want to insert a list, content of which will depend on the user or role. So I think I want to insert some HTML which I'll build in a function somewhere ... but I can't figure out how to get it onto the page in the right place. I want it in one of the divs in my master page. What do I need to put onto the page to allow me to build a string in codebehind (presumably Page_Init) ???

    Firstly, does that make sense? Secondly, am I going about this in the right way? Thirdly, can anyone nudge me in the right direction - I'm sure it's an "easy when you know how" moment...

    Cheers!

  2. #2
    Join Date
    Jun 2006
    Location
    Minnesota
    Posts
    257

    Re: Creating HTML to insert at run-time

    I would think that you could use Response.write to post some javascript that might work...

    Code:
    <SCRIPT LANGUAGE="JavaScript">
    <--
    document.getElementById("swappable").innerHTML="Good evening";
    //-->
    </SCRIPT>
    I found this code on this website

  3. #3
    Join Date
    Jun 2003
    Location
    Toronto
    Posts
    805

    Re: Creating HTML to insert at run-time

    response write will suffice however its important to note that anythign written via Response.Write will appear in the very top of your page. And that can produce undesired results.

    Your best bet is to create a user Control. Inside this user control you just build the html you want and add codebehind on its load event to determine WHAT it should build. This can use the HttpWriter class to write your necessary html in your control. Then you can manually place that control wherever you want in your page.

    So your steps would be.

    1. Create .ascx file .
    2. Write necessary logic codebehind in .ascx file to prepare html using HttpWriter (or another Writer Class)
    3. Maybe you want an xml file with standard html you will be using to generate your control
    4. you place the control at the position (or div) of the main page you want.
    5. when a user logs in the control logic will dictate what should be rendered in the control and it will display on the page.

    hth,
    mcm
    rate my posts!
    mcm

  4. #4
    Join Date
    Nov 2002
    Location
    Devon, UK
    Posts
    212

    Resolved Re: Creating HTML to insert at run-time

    I follow you. Seems a trifle complicated for something I would have thought would be run-of-the-mill but I appreciate the assistance

    I'll let you know how I go!

    Thanks again gurus,
    T

  5. #5
    Join Date
    Jun 2003
    Location
    Toronto
    Posts
    805

    Re: Creating HTML to insert at run-time

    everything that seems simple is complicated...sometimes.

    mcm
    rate my posts!
    mcm

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured