I want to load a .cshtml page inside html page (I dont want to redirect to another page).I tried using
$("#containerdiv").load("folder/Default.cshtml") or $("#containerdiv").load("folder") (html pages load successfully with this method) but when I saw the source code only heading was loaded into containerdiv. Is there other way to do this ?
Try using an iframe. With an iframe you can show the page within the page and view it's code from the same page. Try this
<iframe src="folder/Default.cshtml"></iframe>
Of course, this is only if your not going to anything with server code, which i'm guessing is what you want to do. You can't load server code from an html page because the browser processes the page, not the server.
EDIT:
Try this instead:
<iframe src="FULL_PATH_TO_FOLDER_HERE/folder/Default.cshtml"></iframe>
EDIT 2:
Since that's alot to type everytime, you could also do this, see if it works:
<iframe src="./folder/Default.cshtml"></iframe>
You can't load the cshtml directly, you need to call your controller which should return a partial view of the cshtml file
Related
I have an ASP.NET web app with a standard default.aspx, from within which I need to load a html page from another site (all internal intranet) and pre-populate form input controls on that loaded html page using ASP variables. Specifically, username / pwd on a login form based user details loaded by the aspx from a db. The html page also contains a considerable amount of js (shouldn't directly impact this question though).
Not sure of the best route to approach this. I have considered:
1. Loading the html page in a frame, then somehow manipulating it's DOM from another frame loaded from the aspx.
2. Loading the html during aspx page load or render, then replacing the relevant sections of the html with the new values.
I have had a stab at both approaches and ran into issues. With (2) the resulting HTML isn't recognized as HTML by the browser at all (despite the written response being just the original html relayed from the original site). I can see the HTML source in the browser, but the page itself appears blank.
Answers warmly anticipated. Thank-you.
1.if you want to go wityh iframe
You can easily modify values from communicate between parent window and iframe
from parent to iframe function
document.querySelector('iframe').contentWindow.ChildFunction(33);
from chhild to parentfunction
parent.parentfunction("4rom child")
make a function in iframe that accept an object (from parent) and populate it in.
make a function in parent that accept an object (from child) .
2.how are you "Loading the html during aspx page load or render,"
- ajax or something else?
-making a user controll
both should work fine .
( could you tell how are you loading html ?)(as it should have worked)
I'm learning Servlet now, and I was wondering if it is possible to generate 2 html content at once. I would like to generate an html page which is holding an iframe which also has a content. Is it possible to load 2 html page at once in Servlet?
yes this is completely possible. All you have to do is complete your code for html page which is going to be displayed in the iframe.
Now in servlet you have to write the html code for displaying and call the iframe in servlet.
So when your servlet will run on the server it will be running html code of servlet + iframe (which is displaying another html content)
I'm trying to capture div#map-canvas from my site, www.RichBlocksPoorBlocks.com, to make an iframe that people can embed anywhere.
Here's my iframe
<iframe src="http://www.richblockspoorblocks.com#map-canvas" style="width:600px; height:400px;"></iframe>
It goes to div#map-canvas, but it also loads the rest of the page as well. I'd like that div to be the only thing in the iframe.
Is this possible with an iframe?
To achieve this, it would be easier to create a separate .php or .html document which contains only the parts that you want to show in the iframe and exclude everything else.
So, instead of the iframe pointing to "http://www.richblockspoorblocks.com#map-canvas", it would point to something like : "http://www.richblockspoorblocks.com/map-canvas.php".
This would be a very quick and efficient way of doing what you want, and doesn't require any outside libraries or javascript.
When you call http://www.richblockspoorblocks.com#map-canvas the hash will probably cause the browser to look for a corresponding <a name="foo">bar</a> so this won't work using an iFrame.
What I would recommend doing is writing a script which you call from your iFrame which accepts the name of the page fragment to load. I know using jQuery's $.load() you can call an element ID to load a page fragment, and I think it's also possible in PHP too...
You cannot use hash links in iframes.
You can and should use, few lines of you'r favorite server side language to create the specific content you want to render and then link to it. in that way, you'r server will send out to the end user only the desired data and also it saves bandwith and loading time.
I have login button in the left side of the web page, now I want this to be available at any page in my site, however I don't want to reload the whole page all the time, when the user login I want to keep his name constant on the left side which is there for the all site.
I want to avoid frameset this is realy problematic for my site.
The site id built with JSP.
what are the options.
I thought of using <jsp:include page=''> and try to change the page url dynamicly but this is impossible since it is compiled to servlet and this it server side.
Also if I include leftSide.jsp in each page than leftSide does reload for every page.
please advice, there must be a solution for this simple and very common problem.
You can use <%# include file="login.jsp" %> in all pages. The login.jsp can contain the common code
You can use a template engine, like tiles, freemarker or sitemesh.
With either of these, if you don't want to reload, you need ajax. Perhaps using jQuery.
call the login/logout server-side action using ajax
update the box (make it a <div>) accordingly, with javascript
Is iframe should not be used ever?
how screen reader behaves with
iframed content?
Without iframe how we can embed any
PHP page into asp.net based site?
What are cross browser alternatives?
I don't see why using an iframe is a problem.
If you can't use it then you could either use javascript to download and insert the generated html from the php page, or you could download the html in your asp.net server-side code and insert the html in a control.
Either approach should work well, but using javascript across domains is difficult.
If you go for the asp.net server-side approach you could do the following:
First insert an control where you want to include the html from the php page
In your Page_Load event use the WebClient to download the html as a string
Remove the <html>, <head> and <body> tags so that you only have the pure html markup. You may want to add any script- and css-references to your page if they are needed.
Assign the cleaned html to the Label controls Text property.
This will work, but there are a few points to make:
First you should consider if you trust the source of the php page. If you don't then you will want to do some extra cleaning of the html before displaying it
Second, you will probably want to cache the downloaded html so that you don't have to download it for each page view.