Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Write Html code In aspx page

Tags:

asp.net

I have whole page HTML in my database and i want write that html code in to an aspx page. Means it replace old html code from new one.

Is there any other way to write html code in to aspx page.

like image 536
Pankaj Mishra Avatar asked Oct 26 '09 12:10

Pankaj Mishra


People also ask

Does ASPX use HTML?

The output of an aspx page is an html page. It's just a way of assembling the content and markup dynamically, on the server side,as opposed to typing it all out beforehand as static html.

How do I write text in ASPX?

Content = "text/html; charset=utf-8"; head. Controls. Add(contentType); HtmlGenericControl title = new HtmlGenericControl("title"); title. InnerText = "Untitled Document"; head.

Can we write C# code in ASPX page?

yes, you can write C# in aspx page. Yes, if you want write c# code in same aspx file. First time you add new item > web form > check/uncheck place code in separate file.


2 Answers

Id.InnerHtml = "html code";

its worked for me

like image 89
Pankaj Mishra Avatar answered Sep 21 '22 23:09

Pankaj Mishra


Use HttpHandler to do this. Just read the HTML page from the database and flush it to response stream.

Be sure to map the handler with a route in web.config

CODE: PageWriter HttpHanlder

using System;
using System.Collections.Generic;
using System.Web;

/// <summary>
/// Summary description for PageWriter
/// </summary>
public class PageWriter : IHttpHandler
{
    public PageWriter()
    {
        //
        // TODO: Add constructor logic here
        //
    }

    #region IHttpHandler Members

    public bool IsReusable
    {
        get { return true; }
    }

    public void ProcessRequest(HttpContext context)
    {
        try
        {
            string htmlPageFromDatabase = string.Empty;

            //Read the HTML Page content into htmlPageFromDatabase from database

            context.Response.Write(htmlPageFromDatabase);
        }
        catch (Exception ex)
        {
            context.Response.Write("Page could not be loaded due to " + ex.Message);
        }
    }

    #endregion
}

WEB.CONFIG

<httpHandlers>
      <remove verb="*" path="*.asmx"/>
      <add path="PageFromDatabase.aspx" verb="GET" type="PageWriter" />
</httpHandlers>

After this, You cann access your page from http://yourserver/yourapp/PageFromDatabase.aspx [ ex: http://localhost/mywebsite/PageFromDatabase.aspx ]

like image 36
this. __curious_geek Avatar answered Sep 19 '22 23:09

this. __curious_geek