Get html code of aspx page from code behind

Hi all,

Do you how we can do what I mention in the title?

aspx code

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Header.aspx.cs" Inherits="Header" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">

<script type='text/javascript'>

 Is there any way that in the code behind I can have the above string?. Actually I like to get the content in the <!--js-->...<!--/js--> for overriding the render method

 Thank you


12/29/2007 7:18:24 AM 93655 articles. 5 followers. Follow

3 Replies

Similar Articles

[PageSpeed] 49

You can get the controls inside the Head section of the page:

        foreach (Control c in this.Header.Controls)
            if (c.ToString() == "System.Web.UI.LiteralControl")
                Response.Write("<b>" + ((LiteralControl)c).Text + "</b>");

All JavaScript, CSS, etc ... sections are represented in ASP.NET by Literal controls when ASP.NET runtime represents the sections in the control tree. Now, in the loop above, whenever you reach a LiteralControl, you can use a Regular Expression to get the script you want!

I am not an expert in Regular Expressions and I usually go to to browse a lot of regular expressions there!

Hope this helps,

Bilal Hadiar, MCP, MCTS, MCPD, MCT
Microsoft MVP - Telerik MVP
12/30/2007 7:43:41 PM

You can use RegisterClientScriptBlock, RegisterClientScriptInclude, RegisterStartupScript methods of the ClientScript class.

For example:

Please remember to Mark this post as Answered if it serves your purpose so that issue can be closed and others can refer.
12/30/2007 7:54:24 PM

Thank you, haidar_bilal and SKVSKV

I can not use these methods 'cause there're no server controls on my .aspx page. Anyway, I've got my solution: read aspx file by I/O-stream classes



1/5/2008 8:07:21 AM

Similar Artilces:

how can i convert code behind web forms pages to inline code pages
hi all of you, I have a problem, a have registered a free space at Brinkster , so i can just upload my files there one by one, but can not install my web application directly, and i have to upload my projects there, so one way is o convert all my VS.NET web application which is code behind, convert that into inline code, so how can i do that Thanks in advanceWarm Regards,Prajesh Kumar JhaE-MAIL : Convert from Code-Behind to Code-Inline: Darrell Norton, MVPDarrell Norton's BlogPlease m...

Web Forms Designer error
Hi, The web forms designer keeps adding things in a generated InitializeComponent() method. I believe these things shouldn't be there because I've made a new webform with the same code that doesn't add the same stuff. Is there anyway I can see the Web Designer code? Thanks. Just expand out the hidden #region. It is labeled Web Form Designer CodeStarting with ASP.NET 2.0? Look at:Programming Microsoft Web Forms My Blog...

Setting width for .net controls in code(.aspx) page using function call in code behind..
Hi,  Currently I am trying to set the width of the Table as follows. <asp:Table width="<%=GetWidth()%>" >   and code behind protected Unit GetWidth() { return Unit.Percentage(50); }     It's not working. I know that it works if I set the width complete on some page event(like page_load) of code behind....   Is there a way to maintain the same syntax like calling code behind function in design page...i.e. calling function of .aspx.cs in .aspx page and assign the width as shown above.   Thanks and regards, Giridhar...

how to split out code in HTML to code behind form?
A lot of samples in books are code in HTML but I like to read code behid form. How to split out code in HTML to code behind form? That is, all vb code in a file and all html in another file. I try many times, there are still errors. what editor are you using? CodeBehind is supported by VS.NET and (IIRC) WebMatrix - what are you using?RTFM - straight talk for web developers. Unmoderated, uncensored, occasionally unreadableJason Brown - MVP, IIS I use both. If you create a new project, it is ok. But if you try to run the sample from book, for example, the book "ASP.NET DATA...

How to code SqlDataReader, code-behind a SqlDataSourceID in aspx page?
I copied a Pre-selection code for a CheckBoxList control from Internet to my aspx.vb file, then got the following error message because I defined a DataDourceID for the CheckBoxList control in aspx source file.   ************************************************************************************************************************************************************************Exception Details: System.InvalidOperationException: Both DataSource and DataSourceID are defined on 'cblTests'.  Remove one definition.Source Error:   Line 81: Dim DataTextFi...

How to insert HTML code from code-behind outside of form?
I need to insert some html code inside of the <body>, but before the <form> tag from my code-behind. Any ideas how to do this? Thanks You can place a literal control outside your form and then write your HTML as a string to the Text property of the literal. Simon...

Generating HTML code from aspx code behind and echoing to the user
Hi all,I've just started out in the world of ASP programming and was wondering if it was possible have a method which would generate HTML from my 'code-behind' (basically what I want is a dynamic AJAXed table which reads in some XML) which I can then basically echo back to the user and place within a certain section of the HTML?Much appreciatedPaul Kiddie Read up on web user controls, it is probably what you need to develop. Another related question in how I'm parsing the XML on the server side aspx.cs script - I've put an Arraylist initialisation ...

Using code compiled code behind instead of aspx pages
Hi There, I have some code I wish to release to a customer (its a photo gallery with upload, autothumbnail and watermarking facilities). Currently this is in one stonking vb aspx file, and I was working under the (wrong) assumtpion I could just obfuscate the code ala html mangler (which I find I cant). So, I need to create a .vb code behind - which is ok - I dont mind the extra work, but having read some bits about this I have the following questions and would be grateful if anyone could point me in the right direction. 1) I dont particularly want the user screens html source vie...

coding in aspx.vb page of web form
Hi guys I m generating a repeater control by code it in aspx page(html coding) Here is the coding: <asp:SqlDataSource ID="datasrc" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString1 %>"                        SelectCommand="SELECT [heading_t], [comment_t],[links_t],[imgurl] FROM [user_news_t] ORDER BY priority DESC" ProviderName="<%$ ConnectionStrings:ConnectionString1.ProviderName %>">&...

getting code behind variables in .aspx html
Hi folks, I've done something similiar to this before when databinding, but now am looking to output a variables declared and initialised in the code behind aspx.cs file into my .aspx html soucre file. Basically I have an image which has an onMouseOver javascript call which swaps one image for another and which works fine, however onmouseout I need to revert the image to original image. The original image displayed is determined by reading a DB value and is not nesscerily the image outlined in the ImageUrl property. <asp:Image ID="Image1" runat="server&quo...

Get Html code that renderred by aspx page
Hi all:     Anyone knows how to get the html code that renderred by aspx page. (i.e the code that appear when "view source").     What i want to do is to grab part of the html code and put it into a html file and may convert it to pdf later on.  i.e get the outgoing html string. like this: Protected Overrides Sub Render(ByVal writer As System.Web.UI.HtmlTextWriter) 'Get the rendered HTML Dim sb As New StringBuilder() Dim sw As New System.IO.StringWriter(sb) Dim tw As New HtmlTextWriter(sw) Dim ...

Adding HTML code to an aspx Web Form
Hi, I have some HTML code provided by Google to provide a search box that will link to a custom results page. It works fine when used on a HTML page but if I copy the code to an aspx web form it errors out and fails miserably. The HTML code is: <!-- Search Google --> <center> <form action="" method="get"> <input name="ie" type="hidden" value="UTF-8" /> <input name="oe" type="hidden" value="UTF-8" /> <table bgcolor="#ffffff"> <tr> <td> <input maxlength="255" name="q" size="25" type="text" /> <input ...

C# code in code behind vs inline C# in aspx pages
I know that when there is C# code in the code behind of an aspx page the assembly needs to be recompiled and released when the code is changed.  But what if the code is inline (actually INSIDE the aspx page)?  What happens then?  Is there some type of assembly in a temporary directory that gets created?  If so, if the aspx page is just opened up in a text file and the cs is edited will this temporary assembly get updated? This is just a series of questions I've been curious about but don't have any idea how iis works.  Any answers/points to readings would be...

Sorting, Paging in Gridview with Code Behind (Code Behind ONLY!!!)
Does anyone know of a definitive tutorial of VB code-behind for paging and sorting parameters for GridViews?  I've been all over this site and I know more than I need to know about the SortExpression parameter, the ASP.NET tutorials on Paging and Sorting, and the many postings on these forums for same.  Please don't take the copout approach and give me links for what I've already read.  I'm specifically looking for something that gives a detailed explanation for such things as the PageIndexChanging, PageIndexChanged, SelectedIndexChanging, SelectedIndexChanged,...

Web resources about - Get html code of aspx page from code behind -

New York Times: Pro-Gun Politicians Are Helping 'Would-Be Killers' Commit Mass Shootings
As the number of mass shootings in 2015 continues to climb and, by some counts even outpaces the number of days so far in the year, The New York ...

Harrison Ford tweet proves that Star Wars spoilers are everywhere you look
Disney and LucasFilm have been careful to avoid spoilers for The Force Awakens — even with the relentless barrage of trailers over the past few ...

Scott Weiland Dies At 48, Bandmate Arrested For Cocaine Found On Tour Bus
The music world was rocked by the news that former Stone Temple Pilots front-man, Scott Weiland, was found dead on December 3, in Bloomington, ...

Donald Trump interrupted ten times at NC rally
USA TODAY Donald Trump interrupted ten times at NC rally USA TODAY At a rally of around 8,000 in North Carolina Friday night, Trump was interrupted ...

Economics Of A Death Star Revealed: ‘Star Wars’ Battle Stations Would Have Caused Galactic Financial ...
As the release of Star Wars: The Force Awakens looms, the internet is flooded with content (both crazy and otherwise) dissecting the events of ...

Northern Ireland Court to Rule on Same-Sex Marriage After Christmas
A judge at the High Court in Belfast, Northern Ireland has been hearing arguments for two days challenging the nation’s ban on same-sex marriage ...

Messy midway: Paris draft climate deal ready, long way to go
LE BOURGET, Paris (AP) — Negotiators adopted a draft climate agreement Saturday that was cluttered with brackets and competing options, leaving ...

Activists go thru 5 stages of grief for the climate change campaign
By Larry Kummer, from the Fabius Maximus website Summary: Climate activists have begun to see the failure of their campaign to get public policy ...

Planned Parenthood clinics are open, but on guard
CBS Local Planned Parenthood clinics are open, but on guard Sacramento Bee Bulletproof glass and armed security are nothing new at medical ...

Texas Admits That It Doesn't Have the Power To Turn Away Syrian Refugees, After All
After announcing from the hilltops that it will not, under any circumstances, no-way-buster, allow any more Syrian refugees to enter its state ...

Resources last updated: 12/5/2015 5:07:14 PM