C# - To Intercept And Modify The Html Output Stream In .net, To Combine The Javascript?

Jan 5, 2011

Is there some way to intercept the HTML output stream in asp.net and make modifications? Eg using httpmodules or something? I know this is possible using java servlets and assume there must be an elegant way to do this with asp.net.

My purpose is to combine the many javascript files into one composite script which has been minified/packed, to make the page load faster.Eg, if my page normally outputs the following in the page head:

<script type="text/javascript" src="/scripts/blah.js"></script>
<script type="text/javascript" src="/scripts/yada.js"></script>

I want to replace that with the following:

<script type="text/javascript" src="/scripts/all.js"></script>
(also i realise i'll have to create all.js somehow).

View 2 Replies


Similar Messages:

Save A File / Stream To Local Folder From Response Output Stream?

Feb 22, 2011

I have an excel file in my Response Output stream. I can Open the stream as a file after a prompt, but it doesn't seem I can save it directly to a specified folder on my client.

View 1 Replies

Web Forms :: How To Combine C# And Html/javaScript

Apr 17, 2010

i got a question that realy bothering me .... for the last 24 hours ...

how to combine c# and html/javaScript .....??

so ... the question :

for example i create a varible in my asp.net form .......

int variable = 2;
// some function .....
protect int makeItdouble(int variable)

{

return variable*2;

}
variable = makeItdouble(5); // some code i

and now i want to take this "variable" into my my javascript code .... this important thing is that i want thet this function will run first .... (the C# function)cus i take first my DataBase from the server and that prosses him more with some javascript code ...

View 10 Replies

Intercept Output From Default Handler With Another HttpHandler?

Mar 18, 2011

I have set up an HttpHandler for *css to do some simple parsing:

<handlers>
<add name="CssHandler" verb="*" path="*.css"
type="MyApp.CssProcessor,MyApp.Assembly"/>
</handlers>

All was well until I added a resource that loads a css file dynamically, e.g.

<link rel="stylesheet" type="text/css" href="/loader.ashx/module.resource.css" >

To my surprise, things went horribly wrong. The custom http handler intercepts this, but since it's designed to just load files from the file system, it doesn't work. I realize that, technically, it matches a pattern *.css but that seems an odd behaviour, since the actual resource being requested from the web server is *.ashx and the css is only after the file path, as a parameter.

Is it possible to make the filter for a handler only apply to the actual server resource name?

Alternatively (and actually I'd like to know how to do this anyway) -- what I would really rather be doing is intercepting the output from the default css handler. That is, rather than having all my own code to actually load files from the file system in my CSS handler, it seems it would be far simpler to just take the response from the default handler and filter it. Which would have worked properly in this situation.

Finally, in either case, I'd much rather be filtering on resource MIME type text/css rather than intercepting requests by name, since what I really want to do is filter any CSS (rather than anything that happens to be named "*.css"). how to do this?

View 1 Replies

MVC :: Writing To View Output Stream From Code?

Sep 19, 2010

how does the code within the <% .... %> brackets write to the output stream of a view?

Where view code that looked like the following would write the HTML for a <table> to the output html of the view.

<%
ToViewOutput( "<table>" ) ;
ToViewOutput( "<tr>" ) ;
ToViewOutput("<td>row1. cell 1.</td>") ;
ToViewOutput("<td>row1. cell 2.</td>") ;
oViewOutput("</tr>") ;
ToViewOutput("</table>") ;
%>

View 3 Replies

C# - Stream Command Line Output To A Webform?

Jul 9, 2010

Is there a recommended or good way to stream the output messages asynchonously to a web form so there's some indication of progress? A bit like TeamCity does for build scripts. Should I be polling a webservice? Using the OutputDataReceived event? Turning off buffering?

View 2 Replies

Outputstream - Can Get Read Access To The HTTP Output Stream In Web Application

Feb 22, 2010

I would like to read all content that's been written to the output stream. I'm attempting to do this using an HTTP module, and it seems like the obvious timing would be when handling the PreSendRequestContent event.

However, if the output stream seems to be set to write-only, as I can't read using a StreamReader. Is there a way I read and re-write the content without writing my own IIS module?

View 1 Replies

Custom Templated Control - To Modify Where Databound Data Is Output To?

Aug 31, 2010

Basically, I have a custom templated control with a custom data container class. When a developer adds an instance of my control to a page, they can define the controls in the LayoutTemplate however they like, as follows:

<ml:MyControl id="MyControl1" runat="server">
<LayoutTemplate>
<span><%#Container.ErrorMessage%></span>[code]...

I would like my control to automatically move the "ml_errormessage" (databound content from Container.ErrorMessage - hard coded token in the property) to be a class of its containing element to make it easier for jQuery to use a selector to find the element and dynamically insert the error message client side. More importantly, I would like it moved out of the way so the class name doesn't get replaced by the content and jQuery can find it as many times as it needs to during the page lifecycle. In other words, I would like the output to look like this without the developer changing the input template or resort to using custom controls in the template:

<span id="MyControl1"><span>
<span class="ml_errormessage"></span>
</span></span>

I would like to move the value using the controls collection rather than resorting to string parsing of the output, if possible. However, when I interrogate the collection in an override of OnPreRender, the control in the template looks like this in the debugger:

{System.Web.UI.DataBoundLiteralControl}
System.Web.UI.DataBoundLiteralControl: {System.Web.UI.DataBoundLiteralControl} [code]...

As you can see the "ml_errormessage" value is nowhere to be found. Upon analysis of the DataBind event of the Control class using Reflector, I see that it delegates the binding behavior to each control. In other words, each control handles its own databinding. However, since I have no way of knowing in advance what control types will be in the template, how can this change be done?

Note: an acceptable alternative would be to add a new HtmlGenericControl (span) in the exact spot where the "ml_errormessage" is and add it as a class to this new control.On a side note, is there an easy way to get the control's output to indent for easy reading during debugging?

View 1 Replies

C# - Intercept An HTML Form Post And Do Some Processing Before Sending It To It's Final Destination?

May 21, 2010

I'm trying to extend the functionality of an ASP.net application that I'm working with. For its logon page, it uses an html form to post to a dll to handle it's login logic. I'm wondering if there is any way to redirect that html POST to my C# code so that I can do some processing and then (and this is the part that I haven't figured out yet) POST it to the dll so that the regular logon logic can continue. I can make changes to the logon page, but the final step must be to do an HTML POST to the dll. I can't change that.

View 3 Replies

C# - Combine Javascript/CSS Into One File Or Two For Better Optimization?

Jan 24, 2011

I am currently working on an c# application that minimizes and combines javascript/css asynchronously in the background to load on to the page which completed. Once the combined minimized file(s) are created, they are saved on to disk and all subsequent requests to the page will load this file.

The reason for this is to assist with performance on the page. I have a concern though, what if the combined file is large, eg 200 kb. Would it be better to combine in to 2 files if this was the case and have 2 separate http requests? The file will be gzipped and cached.

View 3 Replies

Multiple Javascript Files, Combine Into One?

Feb 2, 2011

I am developing in asp.net mvc and using multiple javascript files.eg jquery, jquery-ui, google-maps my own js files etc.for performance should i combine these into one?if so how?

View 4 Replies

MVC :: Return Text Stream Of HTML From Controller Action?

Nov 6, 2010

How does a controller action return an HTML stream as the View? ( in place of the name of the View file )

I want to return a simple "error detected" or "action completed" page to the browser. And I dont want to clutter up my project with yet another view. The return string being "<html><body><h1>Error. Customer xxxx is not found</h1></body></html>"

( thinking about it, better to have a general purpose view in a folder named "Common". Then pass the message text in ViewData. Still curious to know how to return an html stream. )

View 1 Replies

Reading Txt File And Modify Content To A Output File?

Jan 5, 2011

I would like to find a way to read a txt file (in my case delimited by €). I need to change the order of the columns and also add and remove some columns. My output file should be a txt file delmited by ;.

I tried Jet.OLEDB to read the file and put it into a datatable and then used a stringBuilder and streamwriter to get an output file in .txt format. However. This does not me since IŽ, reading the txt file from start to end and my output will be the same. It does not seem like I can have a custom sql statement when reading the file. The only query that works is

Dim da As New System.Data.OleDb.OleDbDataAdapter("Select * from 1.txt", TextConn)

How can I possible modify a txt file?

This is my code for now:

[Code]....

View 1 Replies

How To Modify Raw HTML Of Page On PreRender

May 13, 2010

I want to access the raw HTML code that my ASP.NET System.Web.UI.Page is about to render.

How can i do that? Is there a property or method like System.Web.UI.Page.HTML or something like that.

I know I could loop through the Controls List of the page and get access to all the Literal Controls etc, but I was wondering if there's a direct property or method that can return me the raw html, which I can modify just before rendering the page.

View 2 Replies

Web Forms :: Dynamically Modify HTML Markup

Sep 22, 2010

I have a Master Page as well as a standard Web Form aspx file. What if I wanted to dynamically modify the complete HTML markup in an aspx file (perhaps based on a conditional statement - perhaps in a specific content place holder), how would I go about doing this? Sorry I'm coming from a PHP background so this is why I'm asking such a simple question.

View 1 Replies

Javascript - Response Object Not Returning Excel Stream In Update Panel?

Oct 11, 2010

I am generating an Excel file upon a click of a button in an update panel. It is throwing a parsing error.

If I keep the button outside the update panel it is working fine. Why isn't it working in the update Panel?

Response.ContentType = "application/vnd.ms-excel"
Response.AddHeader("Content-Disposition",
String.Format("attachment;filename={0}", filename))
Response.Clear()
Response.BinaryWrite(WriteToStream.GetBuffer)
HttpContext.Current.ApplicationInstance.CompleteRequest()
Private Function WriteToStream() As MemoryStream
'Write the stream data of workbook to the root directory
Dim file As MemoryStream = New MemoryStream
hssfworkbook.Write(file)
Return file
End Function

View 1 Replies

AJAX :: HTML Editor - Change The Output Generation Properties Of The HTML Editor?

Jun 22, 2010

I was wondering if there was an easy way to change the output generation properties of the HTML editor.

I need to change it from the current XHTML standard (spans, etc) to legacy styles; <b>, <u>, <i>, etc.

View 2 Replies

Modify The POST Data In Javascript?

Sep 29, 2010

I have a scenario like below:I navigate to the reader page with the below form data

<form id="mainForm" action="Reader.aspx" method="post">
<input type="hidden" id="bookId" name="bookId" />
<input type="hidden" id="startPageId" name="startPageId" />
</form>


Initially the hidden variable values will be bookId=1 and startPageId=5

I navigate between the pages by using javascript and assume the startPageId will now change to 8.I want the new value to be stored in the above form data and want to submit the same page with different form data

bookId=4
startPageId=10

When I click on the browser back button, I want the user to be navigated back to the BookId=1 and startPageId=8

View 2 Replies

Modify Every File That Contains A Javascript Reference?

Mar 24, 2010

I have some pages that reference javascript files.

The application exists locally in a Virtual Directory, i.e. http://localhost/MyVirtualDirectory/MyPage.aspx

so locally I reference the files as follows:

<script src="/MyVirtualDirectory/Scripts/MyScript.js" type="text/javascript"></script>

The production setup is different though. The application exists as its own web site in production, so I don't need to include the reference to the virtual directory. The problem with this is that I need to modify every file that contains a javascript reference so it looks like the following:

<script src="../Scripts/MyScript.js" type="text/javascript"></script>

I've tried referencing the files this way in my local setup but it doesn't work.

View 3 Replies

Strange Characters After HTML Output

Feb 12, 2010

Recently I started a project and added a HTML file in it. I modified the HTML file and run it in Visual Studio to see the output. When I tried to validate the HTML file, I found some strange characters got appended. This is quite annoying, although I am not able to see those unexpected characters, I wonder what is the cause of the problem. I didn't adjust anything in control panel of the IIS server, I didn't modify the Web.config file. I tried to add another HTML file and put the same content into it, the same problem occured. Could someone tell me how should I troubleshoot the problem?

View 7 Replies

Get Only JSON String As Output Without Any Html

Jan 22, 2011

I am developing a webiste in ASP.NET. On one of the pages page named menu.aspx, with the help of a certain login, I am getting the output in this format

foo({"1":"Jeff","2":"Mik","5":"Tom"});

I am using this code to get the output on the JSON form.

[Code]....

However, I must get the output only in simple JSON on the page without any HTML.

For eg: Here's the screenshot showing the source of the output page. [URL]

Notice that it has only the JSON string as the output.

And here's the screenshot showing the output page source (with HTML). [URL] .This HTML is what I have to remove. How can do I do this? The full code of menu.aspx.cs is putup here. [URL]

View 3 Replies

Parse Page HTML Output

Sep 27, 2010

I'd like to know one (or more) ways to parse the HTML page output. I'd like to detect some patterns on the HTML that will be send to the client and log some info if present.

View 2 Replies

Output Object Properties To HTML?

Dec 7, 2010

Idealy i would like to get a web-page that looks like the popup-windows that you get in Visual Studio when you click an object while debugging. So if the object contains any arrays, i'd also like to see what's in them, and for all those objects inside i would also like to be able to go deeper into those objects.

The reason i'm asking this, is that I can't debug my code locally (because it uses a web-service that will only run on the production), and I can't install Visual Studio on the production server, So i need to be able to actually debug on the production server. I can write my code locally though, and upload it to the production.

View 3 Replies

Output Query Results In HTML?

Mar 11, 2011

i query a database for retreiving all the columns. I will probably have many rows. Im trying to output the query results into an html table. This is what i have so far:

[code]....

How could i store the many rows and output them using html as soon as i open a page?

View 3 Replies

MVC :: How To Redirect The Output Of A View To Html Or Pdf

Jan 17, 2010

How can i redirect the Output of a View to html or string or PDF?

[Code]....

I whant to redirect that action to a pdf but all code i have found is on c# and i cant get it to work.

View 3 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved