Rendering "partial" pages in ASP.Net? (without the <html> and such) - c#

I am trying to make use of jQueryUI AJAX tabs in my ASP.Net Webforms project.
I have come up against a wall though. For AJAX, you must render only a partial page(no <html> and such elements) by an external URL. How would you best do this in ASP.Net? aspx files require things like a <html> and <head> tag so those wouldn't work so the only thing that comes to mind is using cumbersome ashx files. Am I just over thinking this? Is there an easier way?
Edit:
So apparently <html> and such tags are not actually required. So what differences are there to rendering without the full page headers? Will some controls not work? Why wouldn't they?

There's no reason your .aspx pages have to have <html> tags.
Just go ahead and build .aspx pages with the content you want on them and point your jQuery UI tabs to each URL and it will wire up nicely.

ASP.Net does not require any particular HTML tags.
You can make a partial page as an ASPX that includes whatever you want. (Although some server-side controls might not work)
In fact, you can even make an ASPX page that renders aribtrary (non-XML) plain text.

Related

How to isolate one page using "X-UA-Compatible" from Master Page

I have an application with a master page. The page inherits the master page. Prior to IE9, we had no issues in regards to our image viewer. After some research, I have found that I need to use the "X-UA-Compatible" in the meta tag. However, this issue is only occurring on one page.
If I put <meta http-equiv="X-UA-Compatible" content="IE=8" /> in the master page, the problem is solved, but that means the rest of the application will have to use this as well. Is there a way for a single page to use that meta tag without effecting the rest of the application?
Thanks for any input.
There are many ways, e.g.:
put the Response.AppendHeader("X-UA-Compatible", "IE=8"); to the
codebehind of that single page
Put a placeholder to your masterpage and fill it with the meta tag only on that single page

In ASP.NET MVC, how to make separate files for each module in a page?

A page has several "modules" (parts of the page)
Each module has css, js, and html.
In the final page we'd like to put the css parts at the top, and the js parts at the bottom.
The masterpage has ContentPlaceHolders.
We created a ContentPlaceHolder for css, one for js and one for html.
Problem is, each one is defined with an id, so it can be "accessed" only once using <asp:content.
In addition, if each module is placed in a partialView(ascx file), these tags do not work (AFAIK).
We currently break apart each module, putting its css manually at the start, js at the bottom, etc.
This makes for bad coding and hard maintainability.
Is there a way to do this nicely?

Timers from ASP.NET to MVC Razor

I'm moving an app from ASP.NET/C# to MVC and I have some Timers <asp:Timer>
I'm trying to find exactly the same tool for MVC (Html5 or DevExpress) but seems like there is not or at least my intellisense doesn't show it.
Anyone knows about it and can post the squema of it?
You will need to use Javascript yourself.
Take a look at window.setInterval() or one of the many jQuery timers.
Another option, that doesn't involve javascript is the HTML META tag.
example:
<meta http-equiv="refresh" content="30">
content is specified in seconds. META elements live within the HEAD element.

How to refresh just a specific portion of an HTML page?

I have one HTML file containing several <div> elements. I want to refresh just part of the page using either JavaScript or C#. Can someone help?
I am trying to do it this way:
document.location.reload(document.getElementById("contentdiv"));
It reloads the whole page. I wish to reload contentdiv. If contentdiv is at the middle of the page then it should load only that part.
Thank you.
You could move the contents of everything you want reloaded into an external file, and either use the <iframe> tag and only refresh that frame, or you could use JavaScript and refresh the div with Ajax.
Ajax isn't that simple to explain in a short answer, but you can find plenty of information on it here: http://www.w3schools.com/Ajax/ajax_example.asp or if you use a framework like jQuery ajax is much easier.
iFrames can be implemented (on mypage.html, for example) like so: <iframe src='mypagecontent.html'></iframe> and in mypagecontent.html you could use <script type='text/javascript'>window.location.reload();</script> to refresh the frame.
Not sure if this is what you're looking for, but hope it helps somewhat.
What ASP.NET Framework are you using? If you are using Web Forms, look into UpdatePanel

Opening an external page inside our page

I used to implement this above title by using iframe but now I dont want to use it any more I have some plans in my mind I need to implement them by opening an external page inside our asp.net page without using any iframe I have only simple aspx page with div tage and panel and some other serverside componants, I just want to know how I can do it without iframe ? I don't want to design new complex control but I am looking for some methods can do that for me.
I have to mention that I need to control area which is loaded by external site as the same as iframe but the difference is that iframe can not handled by ajax even you put iframe inside the update panel your page has refresh and postback while you are changing the src value programmatically (in c# code) so we have to design some others methods what is the solution ?
I thought I can make request an get some html and show into div but I couldn't to implement it.
You could
Make a WebRequest on the server-side and then set the div's text to HTML returned
You could make an invisible iFrame to make the request and then use JavaScript to grab the HTML from the iFrame and put it in a DIV. (EDIT: Comment suggests this won't work)
You can't generally make calls (like XmlHttpRequest) to external websites because of cross-site scripting issues.
Your direct request, "opening an external page inside our asp.net page without using any iframe" is not possible, by design.
You mention AJAX. You can use AJAX to load your page, remove the headers (or do that serverside) and replace the <body> tag with a <div> tag (or do that server side too). This way, you can place the contents of your page anywhere you like. As a container, I suggest you use a block level element, a <div> would suffice.
The only (!) problem here is: cross-site requests like this are not honored by browsers. You can solve this server-side by loading the page from elsewhere using WebRequest or similar means.
Depends on where you'd like to merge the data. If you'd like to merge the data on the client browser, your only other option besides frames is to use Javascript/Ajax.
You can do a jQuery.ajax() on page load and use the html() method on a div to populate it with the textual result of that AJAX call.
Try to use as little of the WebForms control hierarchy and life-cycle as possible. It sounds like your problem can be fixed with AJAX if you don't mind the second request on page load.
If you would like to merge the content on the server side ( rarely the right thing to do ) you can use System.Net.HttpWebRequest to get and merge the data before returning it to the browser.
there's no substitute for an iframe in your situation. you're not going to be able to make ajax requests to the other site due to security concerns. you could retrieve the contents of a single page server side and render it to the client but none of the functionality will be included, since the content is now running in the context of your own site.

Categories