Display HTML content without showing its relative path in ASP.NET

Discussion in 'ASP.NET / ASP.NET Core' started by Senor Engineer, Jul 5, 2014.

  1. Hello,

    I would like to show the HTML content (resides within the code repository) within ASP.NET page. Based on business logic, I call the HTML file dynamically, so <iFrame src=" may not work.

    Thinking of iFrame or Div. Can you tell me how I add the HTML content dynamically to Div or iFrame? (I should not redirect to the HTML page using Response.Redirect (I can if there is an option without appearing the HTML page relative path).

    Any help is appreciated.

    I used Div tag

    <div id="divShowHTML" runat="server" style="width: 100%" onscroll="yes">

    divShowHTML.Visible = true;
    divShowHTML.InnerHtml = "http://localhost:32423/Files/ProductsList.htm";

    The result I see is (instead of actual content) - please help
    http://localhost:32423/Files/ProductsList.htm
     
  2. RayH

    RayH DiscountASP.NET Lackey DiscountASP.NET Staff

    Generally, what I do is to code the HTML markup first, store it in a string, and place a label control on the page. Then I set the text value to the string. What you're trying to do seems like it would break W3C Validation. There's probably other ways to do this, but I found this to be the easiest.
     
    mjp likes this.
  3. Ray,

    Thank you for the help !!!

    I want to see if there is any other alternative instead of preparing the string builder and there are no alternatives available. I have about 10-12 HTMLs dynamically I have to show based on the selection of features however the HTMLs are kind of secured, so I'm asking. I tried for one HTML taking the source into StringBuilder and got it worked.

    Thanks for the reply, my earlier question is resolved by you.

    Now, my next question (kind of extension to previous question):

    Same scenario above:

    Display HTML in Div tag inside (ASPX Prepare StringBuilder, use div1.innetHtml = sb.Append(XXXXXX).ToString;)

    Question :

    The HTML in Div tag has hyperlinks to replace with pdf and xls files (with relative paths, I can change it to ../PDFs/XXXX.pdf or ../XLSs/YYYYY.xls). How to control not showing relative path on click of these hyperlinks replacing relative paths of PDF or XLS ? I can explain again if it's confusing to you.
    1. ASPX has HTML (in Div tag - no problem, relative path of HTML will not how address bar will have ASPX page name)
    2. HTML has hyperlinks to PDFs and XLSs, how do I control not showing relative paths?
     
  4. RayH

    RayH DiscountASP.NET Lackey DiscountASP.NET Staff

    I think you would have to use JavaScript according to w3schools to mask the URL. I would also suggest using a Literal control rather than a Label depending on your needs. If you noticed, the Label control will add <span> tags as wrappers around your string.
     
    mjp likes this.
  5. From w3schools link, it appears to me that you asked me to look at the below
    • A relative URL - points to a file within a web site (like href="default.htm")
    That's what I tried to mention earlier, I can try it. href="../PDFs/XXXX.pdf", my goal is, if the PDF is clicked, On the Address bar full path to PDF should not be shown (relative path should not be converted to physical path.

    If possible if I can use same Div that would be wonderful (but we are inside html underneath Div, not sure if I can do Div1.innetHTML as Div belogs to parent ASPX)

    Any thoughts ?
     
  6. RayH

    RayH DiscountASP.NET Lackey DiscountASP.NET Staff

    No, I wanted you to look at this line:
    • A script (like href="javascript:alert('Hello');")
     
    mjp likes this.
  7. Interesting, thank you for the tips !!!
     

Share This Page