Home > ASP.Net, Javascript > Accessing HTML Source code using ASP.NET and Javascript

Accessing HTML Source code using ASP.NET and Javascript


Hi

try this Example :-

<%@ Page Language="C#" AutoEventWireup="true" ValidateRequest="false" CodeFile="Default.aspx.cs" Inherits="_Default" %>
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "<a href="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd</a>">
 
<html xmlns="<a href="http://www.w3.org/1999/xhtml">http://www.w3.org/1999/xhtml</a>" >
<head runat="server">
    <title>View HTML</title>
    <script type="text/javascript" language="javascript">
    function getHtml(txtbox)
    {
        var src = document.documentElement.innerHTML;
        document.forms[0]['txtHtmlSrc'].value = src;
    }
    </script>
 
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:Button ID="btnViewHtml" runat="server" Text="View Html" />
        <br />
        <br />
        <asp:TextBox ID="txtHtmlSrc" runat="server" Height="235px" TextMode="MultiLine" Width="542px"></asp:TextBox></div>
    </form>
</body>
</html>

 
in code behind :-
 

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
 
public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        btnViewHtml.Attributes.Add("onClick", "javascript:getHtml()");
    }
}

Hope this helps

Good Luck

Advertisements
Categories: ASP.Net, Javascript
  1. No comments yet.
  1. February 19, 2009 at 1:59 pm

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: