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.
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.
Content = "text/html; charset=utf-8"; head. Controls. Add(contentType); HtmlGenericControl title = new HtmlGenericControl("title"); title. InnerText = "Untitled Document"; head.
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.
Id.InnerHtml = "html code";
its worked for me
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
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
}
<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 ]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With