in view, i have at the bottom many javascript and jquery code, and i dont like it, so im placing all scripts into one ascx file, and make partial rendering like:
<!--<%Html.RenderPartial("~/Views/Home/StationLogics.ascx"); %>-->
of this ascx file with scripts. So, is there any better way?
cant place it to master page, cause not always i need this scripts, if user get some privilage, he can use some scripts, if not - others
it mat not be what u intended to know but i think that u can place all ur javascript and jquery code in a js file like in yourjavascript.js file and place a reference of js file in your view or the master page page file that the view is inheriting e.g.
<script src="<%=ResolveUrl("~/scripts/yourjavascript.js") %>" type="text/javascript"></script>
You could add your common JavaScript files in the head element of a Master page, and then let your pages reference that master page using the <%# Page %> directive, for example:
<%# Page MasterPageFile="/Views/Shared/Site.Master" %>
Now, all you have to do is update the scripts in your master page, and pages referencing that master page will have the scripts as well.
However, if your scripts are too specific to include in the master page, then your solution is probably fine.
Related
I'am making a dynamic website in which the positioning and components of certain components like the fixed header, menubar, footer etc are common in almost all the pages. So how do I include this fixed components in my every webpage? I'am using JSP and javascript.
Thanks in advance.
If you are including static content then you can use
<%#include file="includes/header.html" %>
or for dynamic content
<jsp:include page="includes/header.jsp" />
From http://docs.oracle.com/cd/E19159-01/819-3669/bnajb/index.html:
Reusing Content in JSP Pages
There are many mechanisms for reusing JSP content in a JSP page. Three
mechanisms that can be categorized as direct reuse are discussed here:
The include directive
Preludes and codas
The jsp:include element
An indirect method of content reuse occurs when a tag file is used to
define a custom tag that is used by many web applications.
The include directive is processed when the JSP page is translated
into a servlet class. The effect of the directive is to insert the
text contained in another file (either static content or another JSP
page) into the including JSP page. You would probably use the include
directive to include banner content, copyright information, or any
chunk of content that you might want to reuse in another page. The
syntax for the include directive is as follows:
<%# include file="filename" %>
For example, all the Duke’s Bookstore application pages could include
the file banner.jspf, which contains the banner content, by using the
following directive:
<%# include file="banner.jspf" %>
Another way to do a static include is to use the prelude and coda
mechanisms described in Defining Implicit Includes. This is the
approach used by the Duke’s Bookstore application.
Because you must put an include directive in each file that reuses the
resource referenced by the directive, this approach has its
limitations. Preludes and codas can be applied only to the beginnings
and ends of pages. For a more flexible approach to building pages out
of content chunks, see A Template Tag Library.
The jsp:include element is processed when a JSP page is executed. The
include action allows you to include either a static or a dynamic
resource in a JSP file. The results of including static and dynamic
resources are quite different. If the resource is static, its content
is inserted into the calling JSP file. If the resource is dynamic, the
request is sent to the included resource, the included page is
executed, and then the result is included in the response from the
calling JSP page. The syntax for the jsp:include element is:
<jsp:include page="includedPage" />
The hello1 application discussed in Packaging Web Modules uses the
following statement to include the page that generates the response:
<jsp:include page="response.jsp"/>
So you may use
<jsp:include page="includepage.jsp" />
You can use
<head>
<?php include("path/webpage.html"); ?>
</head>
Hope someone can help me on this. I manage an ASP.Net website and usually update script files and css files very often. I add current time appended into a single string as a query string parameter (eg: profileImage.jpg?123021) which makes the browser to look for the file without getting it from cache.
How can I do the same thing to all script tags and css links from the server side so that it loads the latest version of the file.
Any help appreciated.
Amila
If your asp.net website uses Master Pages, it should be easy to make these changes in the Master Page file. Look a file with the extension .master. If you are not sure how to make the specific edit, post the <head> area from the master page markup in a new question.
MSDN Master Pages: http://msdn.microsoft.com/en-us/library/wtxbf3hh(v=vs.100).aspx
If your site does not use master pages, then you'd need to create some server-side logic that affects the <head> section of the page. Below are some links to related QA's about injecting script and styles from the server side.
ASP.NET: How to (programmatically) attach a <script> tag, containing a link to .js, to <head>?
How to Add script codes before the </body> tag ASP.NET
I just bought template .Now i want to convert this HTML pages into a .aspx page with .cs with it.Does any one have any way to get through this !?but also keeping the java scripts in the html as it is .Thx!
Create new .aspx page and copy the code from html file. If it contains any javascripts added that as a seperate file and link it
An html file won't have any code in it, so just change the extension to .aspx.
You can then manually add a .cs file, and update the controls to be asp controls as necessary.
Your best bet would be to just create a new page in Visual Studio, and then copy the html over. At some point your going to need to create a Web Site or Web Application depending on your needs, and that will take care of creating the correct <% Page %> declaration and code-behind. You'll likely want to put that template into a Master page really.
I have 2 html page (main and details): the main page consists of a table and a empty div. When the user clicks one a table row, the empty div is filled via AJAX from another page (details page).
On the details page I want to load a Google Map. Also I would like the page to be operational by itself (standalone), not just via AJAX.
So here is my problem:
To use Google maps I have to include this script in head of html:
<script src="http://maps.google.com/maps/api/js?sensor=false" type="text/javascript"></script>
If I include this in the details page, it works fine standalone. But it doesn't work when I try to get it via AJAX from main page. Google server hangs, and doesn't progress.
On the other hand, if I include it in the main page, AJAX works fine, but the details page is not operational on its own, since its missing a vital include.
I'd really like to leave it in the details page, since it has much more logic to be there. Is there any way I can load the script in the main page, from the details page?
Generally what is the best approach with javascript including and AJAX? Keep everything in main page? Or is there any mechanism to load everything into main page, but keep the code in ajaxed pages?
Btw. I'm using jQuery, but it is not really important. This is a design issues, not a library problem.
Since you are not using IFRAME, it is best that you include the JAVASCRIPT in the main page rather than detail page - since you can do and the js will work. This I think will fix the ajax issue for you and the script is loaded once.
I'm moving my script references from < head> in the master to bottom right before < /body>.
This has caused some problems with my load order.
In my master I have a ContentPlaceHolder, and I can use this fine from my Views to add additional javascripts.
But how can I add javascripts to this section from a PartialControl?
If I just include the scripts from the control the scripts will load in the wrong order (The script from the PartialControl will render before the scripts in the master). I need to be able to add scripts from my partial view to my ContentHolder in the page.
How shall I tackle this problem? At first I was thinking of an HtmlHelperExtension, but I can't reach the master page from the HtmlHelper object.
Thanks in advance.