Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

JavaScript block - how to render/place javascript on the right place in the .aspx page?

Posted on 2004-10-26
6
Medium Priority
?
247 Views
Last Modified: 2006-11-17
Hello,


I have a simple javascript script that I want to render on .aspx page but on the right place.
Currently my javascript is located in the Page_Load() event and renders above the <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" > which is wrong.

I would like script to be rendered within e.g. <HEAD> </HEAD> block.

javscript:

<SCRIPT language="JavaScript">
<!--
HideWait();
//-->
</SCRIPT>

Thank you,

-mike
0
Comment
Question by:morpheous_
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
6 Comments
 
LVL 15

Expert Comment

by:Thogek
ID: 12413318
Is there any reason not to just put it where you want it in the ASPX file (i.e., in the designer/HTML view)?
0
 

Author Comment

by:morpheous_
ID: 12481258
Yeah, I because I am performing operations where I measure time it takes to load c# code behind from the the Page_Load is started to the time .aspx content code is rendered.
0
 
LVL 15

Accepted Solution

by:
Thogek earned 200 total points
ID: 12487441
I'm not sure what that has to do with where the JS code lives, but....

If you're currently building the <script>...</script> content as a string in Page_Load, one thing you can try is moving that code to a new property, say:

    protected string HideWaitJS() {
        get {
            // build your <script>...</script> in a string here
            return strJS;  // or whatever you call your string variable
        }
    }

Then, in your ASPX, you can do:

    <head>
    <%# HideWaitJS %>
    </head>

Finally, you'll need to call the page's DataBind() method somewhen -- typically in the Page_Load method -- to bind the <%#...%> site to the indicated property value.

Alternately, you can use

    <head>
    <%= HideWaitJS %>
    </head>

in which case no DataBind() call is necessary, and the <%=...%> simply translates to a Response.Write call during the Render phase.  (Both methods have their plusses and minuses, and their proponents and opponents.)
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question