<!-- #include virtual="/footer.asp"--> in ASP.NET application - asp.net

I need to include a header and footer currently located in an asp page. The page takes the language ID and gives you the correct header for the page you are viewing.
I was going thru this: http://forums.asp.net/t/1420472.aspx and this particular fragment seemed to explain it better tho I could not wrap my mind around it.
Hi, instead of using include tags, you could compose your page this way:
Your .NET application here
You can
then implement in codebehind remote
header and footer download logic and
set them in the Literals' Text. After
downloading from the remote site, I
would suggest to store the header and
footer in the application's Cache to
avoid too many connections to the
remote server. If the same
header-and-footer are shared from many
pages in your project, moving this
structure to a MasterPage could be
useful.
Kindly assist.

Well, it would be applicable if header/footer content is coming from some other (remote) server. So the suggested solution is to
Write code to download header/footer content from remote server
Cache the content so that you don't have to download it again and again.
Use literal controls as placeholders on page and set its text to this downloaded content from code-behind.
Now, this may or may not be applicable to your problem. From where does you get the content for header/footer. If its some helper class/method then you can directly call it to set the literal text. You can even do that is master page making things even simpler.
Edit: Additional information requested by OP
You can use WebRequest for downloading content. See this article to get started.: http://www.west-wind.com/presentations/dotnetwebrequest/dotnetwebrequest.htm
Refer below to get started on caching:
http://www.asp.net/general/videos/how-do-i-use-the-aspnet-cache-object-to-cache-application-information

You can use HttpWebRequest to get the required footer text from the asp page and then use the Literal control to display this text.
This page has an example code about how you can submit value to a page and get the response.

Related

How can I prevent a page from not showing an client side error message when a server side include does not load?

In my ASP app, if there is an error with an include file, the entire page will not load and displays this
These includes are sections of the page. If it does not load, I would just want that part of the page not to load but have the rest of the content load. For example, there is a menu that helps to narrow down a list of dealers, it is a lot of code that I want to replace anyways, so I linked it as an html include.
<!--#include file="/dental-equipment/dealer-selection.html" -->
The reasoning was that:
I could work on a different better block of code outside of the project without having to open to main page.
I would not have to document so much in version control. Because I could work on this outside of the project.
I figured this way I could segregate bugs.
It kept each page cleaner to and more organized.
And even if this include did not load, a user could still view and find dealers.
So while I am at it feel free to point out any noob mistakes I am making with project planning here.

Saving contents of <pre> tag to file on server

I have searched here and googled for this, and I've probably come across an answer, but I guess I don't understand asp.net enough to get it working. As the title says, I'm trying to save the contents of a tag to a file on the server. I'm specifically using asp.net because I'm developing for a website on a WHS box and I'd like to use the already existing FBA.
Using javascript, I can successfully get the contents, but I am unable to work with it from there. From what I've read, it sounds like I need to POST the contents, either a postback or to another page, to save the file. That's what I'm having problems getting working. I can get a StreamWriter created and working, but I am unable to pass what I need to it.
Thanks for any help, and I can post some of the code I have now if needed. JR
You need to use Javascript to send an AJAX request to an ASHX handler with the text as the POST body.
You can then read the POST in the ASHX handler from the Request object and write it to disk.

Odd error with HTML content and attributes disappearing

I have an odd error with an ASP.NET web page (ASP.NET 2.0, C#). For several users at one customer location, on one part of one page, HTML content and attributes are being stripped out. So, something that should look like this:
<p class="adminmainlink">
Add or edit resources
<script type="text/javascript">
var hb526 = new HelpBalloon(
{
title: '',
content: 'Add or edit downloadable file, web links, and text resources associated with a course.'
}
);
</script>
</p>
In the users' source code looks like this:
<p><a></a><script></script></p>
Not only is the content of the HTML tags disappearing, but also the attributes of the tags (the "class" value for the "p" tag, the "href" from the "a" tag).
Other areas of the same page are being rendered fine, with no changes to the HTML. The HTML isn't being generated by a code-behind page -- it's just plain text in the .aspx page. The area that is rendering correctly is in the .master page; the problem area is inside an asp:Content tag.
This error is only happening on one page of the application. Other, very similar pages that use the same .master page are unaffected. I am not able to reproduce this error outside of the client's facility, even when logging in to the client's account. The client is using IE 6 -- we have tested on that, and all is OK. No other customers are reporting a similar problem.
Maybe it's a content blocker or firewall issue at the client's location? Maybe the script is causing the content filtering (other pages use the same script and they display fine, however)?
If it's a code problem, it would seem to affect only the area inside the asp:Content control that is dropping into the .master page. Has anyone seen something like this before? What part of the ASP.NET page life cycle would eliminate attributes and tag content from hard-coded HTML? I could see weirdness happening with a control, but with regular HTML?
Many thanks for your thoughts and opinions!
Are the users using Firefox with AdBlock or some other ad blocking software? I've had strange behaviors in our internal application where certain content was being mysteriously removed, and it turned out it was because a liberal filter was applied, blocking out the word "ad." I noticed "ad_resourcewizard.aspx" was contained in your link. You should have the customers at that location try a different browser or disable their ad blocking software in case it's hooked into their networking software (a plugin for their security suite, for example).
Check whether they have any internet security software installed, and if so, try disabling it.
I know we had an issue with one of the versions of Norton Internet Security, which was stripping scripts out of our CMS pages for one particular client.

Making a static ASP.NET site which has 100+ pages

I am converting an old html based website to ASP.NET, so that we can include more features like AJAX, Databases later on to the site. Currently my task is to create a new .aspx page for each older html page. To keep the layout persistent i have made a master page.
So currently i am building a content page from the master page, then renaming the content page and adding the text from the html page to the content placeholder area. However i was wondering if can cannot write a system, which can act as a Page Thrower.
Each hyperlink when clicked goes to a serverside code, where it requests the page it wants to load. Typically a webserver expects that the pagelink specified in the hyperlink does exist physically, but here what i am trying to do is that. Say the link is for the page "TravelDetails", the page need not exist physically, but the content of it is present in a file in (html format). so the Page Thrower gathers the data to display for that page, it has a master page already, it adds the html of it there and then throws the custom page. This way i don't have to keep 100+ aspx pages, i can do with a single page and maintain another data structure to store the content (static data) for each page. any guidance if my approach is right, and how to go about it?
Thanks
I think you should try some cms avaialable in market like dotnetnuke. Because every time you need to have to create a web page for a html page. In future if there will be any changes then it will take time. While in cms like dotnetnuke you just need to paste your html in existing system. You don't need to do coding again.
DotNetNuke is a free one. There are other Content Management System also available as well. Another advantage is that dotnetnuke is having skin features. So if you change skin at one place. You need not to do it for all the places.
Take a look at ASP.NET MVC. It uses ASP.NET Routing, which may help you.
Alternatively you can use ASP.NET Routing without MVC, too.
Matthias
Just a thought.
Create a page linked to the Master Page. In the content place holder add a Panel.
Let your Page thrower decide which page to display, retrieve the html data & add it to the panel at runtime.
Why don't you create the pages dynamically and then use asp.net caching in order to increase throughput.

Parsing PlainText Emails from HTML Content (ASP.NET)

Right, in short we basically already have a system in place where the HTML content for emails is generated. It's not perfect, but it works.
From this, we need to be able to derive a plaintext alternative for the email. I was thinking of instantly jumping on and creating a RegEx to strip the <*> tags from the message - but then I realised this would be no good because we do need some of the formatting information (paragraphs, line breaks, images etc).
NOTE: I am OK with actually sending the mail and setting up alternative views etc, this is only about getting plaintext from HTML.
So, I am pondering some ideas. Will post one as an answer to see what you guys think, but thought I would open it up to the floor. :)
If you need any more clarification then please shout.
Many thanks,
Rob
My Solution
OK, so here it is! I thought up a solution to my problem and it works like a charm!
Now, here are some of the goals I wanted to set out:
All the content for the emails should remain in the ASPX pages (as the HTML content currently does).
I didn't want the client code to do anything more other than say "SendMail("PageX.aspx")".
I didn't want to write too much code.
I wanted to keep the code as semantically correct as possible (no REALLY crazy-ass hacks!).
The Process
So, this is what I ended up doing:
Go to the master page for the email messages. Create an ASP.NET MultiView Control. This control would have two views - HTML and PlainText.
Within each view, I added content placeholders for the actual content.
I then grabbed all the existing ASPX code (such as header and footer) and stuck it in the HTML View. All of it, DocType and everything. This does cause VS to whinge a little bit. Ignore It.
I then of course added new content to the PlainText view to best replicate the HTML view in a PlainText environment.
I then added some code to the Master Page_Load, checking for the QueryString parameter "type" which could be either "html" or "text". It falls over to "text" if none present. Dependant on the value, it switches the view.
I then go to the content pages and add new placeholders for the PlainText equivalents and add text as required.
To make my life easier, I then overloaded my SendMail method to get the response for the required page, passing "type=html" and "type=text" and creating AlternateView's as appropriate.
In Summary
So, in short:
The Views seperate the actual "views" of the content (HTML and Text).
A master page auto switches the view based on a QueryString.
Content pages are responsible for how their views look.
Job done!
If any of this is unclear then please shout. I would like to create blog post on this at some point in more detail.
My Idea
Create a page based on the HTML content and traverse the control tree. You can then pick the text from the controls and handle different controls as required (e.g. use ALT text for images, "_____" for HR etc).
You could ensure the HTML mail is in XHTML format so you can parse it easily using the standard XML tools, then create your own DOM serialiser that outputs plain text. It'd still be a lot of work to cover general XHTML, but for a limited subset you plan to use in e-mail it could work.
Alternatively, if you don't mind shelling out to another program, you could just use the -dump switch to the lynx web browser.

Resources