473,888 Members | 1,426 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Header JavaScript Write from Class?


I have a complex ASPX page, and in the code-behind I instance an
object that inherits from Class. Upon instantiation, I want the
object to write some JavaScript code at the end of the HEAD tag,
immediately before BODY begins.

How can I do that?

Thanks.

Nov 18 '05 #1
5 1474
localhost wrote:
I have a complex ASPX page, and in the code-behind I instance an
object that inherits from Class. Upon instantiation, I want the
object to write some JavaScript code at the end of the HEAD tag,
immediately before BODY begins.

How can I do that?

Thanks.


Have you tried using Page.RegisterCl ientScriptBlock ()?

ib.
Nov 18 '05 #2
On Fri, 25 Jun 2004 02:51:42 GMT, Ireney Berezniak
<ir************ **@gmail.com> wrote:
localhost wrote:
I have a complex ASPX page, and in the code-behind I instance an
object that inherits from Class. Upon instantiation, I want the
object to write some JavaScript code at the end of the HEAD tag,
immediately before BODY begins.
How can I do that?
Thanks.


Have you tried using Page.RegisterCl ientScriptBlock ()?

ib.


If you absolutely need it in the <HEAD> section, you can try to add an id=
and runat=server attribute to the <HEAD> tag, then in the code-behind,
declare a control variable whose name is the id you just gave the <HEAD>
and declare it as a HtmlGenericCont rol. Then you can reference the HEAD
tag as a control and alter its inner text, etc.
--
Craig Deelsnyder
Microsoft MVP - ASP/ASP.NET
Nov 18 '05 #3
Hi Localhost,

I think Craig's suggestions are resonable and since the ASP.NET doesn't
provide buildin features on editing the Header elements directly,
currently, most ones make use of the Literal control to represent the
<head> area of an asp.net web page.
set the
<head runat="server" id="xxx" >
and then use a LiteralControl in code behind to reference it. Also, if you
want to perform a common framework on handling a group of pages. We still
need to integrate this skill together with the PageControler(b ase page)
pattern. And below are some certain web resources discussing on the
similiar problem:

#ASP.NET Page Templates - Using Inheritance
http://www.codeproject.com/aspnet/page_templates.asp

#Dynamically Adding <HEAD> Content with ASP.NET
http://dotnetjunkies.com/WebLog/bsbl...2/11/7052.aspx

An improvement to RegisterClientS criptBlock
http://www.codeproject.com/aspnet/sc...asp?print=true

Hope helps. Thanks.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx

Nov 18 '05 #4

Thanks for the follow up. I am aware of how to generally write code
in the page header from my code behind class. I am also aware of Page
inheritance and use it a lot.

My problem is that I am generally unsure how to write to the <head> of
a page from within a class that is called by the page itself.

If I have in my code behind:

protected override void Render(HtmlText Writer htmlTextWriter)
{
base.Render( htmlTextWriter );
htmlTextWriter. Write( "bye." );
}

I want to change this to:

protected override void Render(HtmlText Writer htmlTextWriter)
{
HeadWriter headWriter = new HeadWriter();
base.Render( htmlTextWriter )
}

And have my headWriter instance "reach back up" to its caller (the
code behind class) and write in the ASPX header at that point.
Thanks.
Nov 18 '05 #5
Hi Localhost,

Thanks for the followup. As for the "HeadWriter " function, I'm afraid this
seems that we have to completely implement the Page's structure and render
method ourselves since the ASP.NET Web Page dosn't provide buildin support
on processing head area. I still think the means I mentioned in the former
reply is what we can do currently. We need to use LiteralControl in page
template and provide a certain Collection member in the page class and use
this collection to hold header items and when the page is render out,
output the header items into the LiteralControl in the page's <head> area.
Its hard to make it purely programmaticall y without any action in page's
html source. Do you think so?
Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx

Nov 18 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
5897
by: Patrick Gibbons | last post by:
What I would like to do is create header and footer information for my webpages which are created by calling from a referenced .js page . . . for example in Header.js: <script language="JavaScript"> function CreateHeader { document.writeln("<table>") document.writeln("<tr>") document.writeln("<td>")
21
2629
by: Hattuari | last post by:
I'm learning C++ after having spent several years in the computer industry doing both system administration and engineering. I've written code in Perl, Bash, Pascal, Ada, C, Mathematica (hundreds of lines of OO code, not 1+1), JavaScript, Lisp, and Java, as well as C++. Each of these languages has it's strengths and weaknesses. My experience with C++ has shown me that it is by far the most difficult for me to learn. I have the sense...
1
8917
by: Webgour | last post by:
Hi, I'm tring to add a column to a datagrid with a linkbutton as header that can be used to sort the column. The column and the linkbutton are added programmatically (see below). However the problem is that when you click the added column header it doesn't trigger the sort. The code : <%@ Page language="c#" Codebehind="WebForm1.aspx.cs" AutoEventWireup="false"
0
3952
by: Lokkju | last post by:
I am pretty much lost here - I am trying to create a managed c++ wrapper for this dll, so that I can use it from c#/vb.net, however, it does not conform to any standard style of coding I have seen. It is almost like it is trying to implement it's own COM interfaces... below is the header, and a link to the dll+code: Zip file with header, example, and DLL:...
0
2629
by: cedoucette | last post by:
I just wrote code to support sortable columns in a datagrid. It seems to work fine; but, it doesn't look right. The problem is that I have a generic style for links and a different style for the header row - and they conflict. The sortable column apparently uses the generic style for <a> elements and the rest of the header uses "headerRow". Can anyone tell me how to get consistent styles for each column in my datagrid header?
3
1568
by: DigMar | last post by:
Hello, Thi is a newbie question regarding the spacing of words in a header with links. I simply want to space the clickable words on my header bar more horizontally. Here is my code to make more sense: // HEADER MENU OPTIONS document.write('<span class="header">');
0
1364
by: anto.anish | last post by:
Hi , Since, i did not want to write all instantiations in Source file of all template methods for various different datatypes that my client might use, Instead, i choose to write implementation of template methods along with their declarations in the header file. Well, there are also other files in the project, which include this header file as well, which all gets compiled, linked and tested well. #ifndef __ATT_H__
0
2001
by: anto.anish | last post by:
Hi , Since, i did not want to write instantiations in Source file of all template methods for various different datatypes that my client might use, i choose to write implementation of template methods along with their declarations in the header file. Well, there are also other files in the project, which include this header file as well, which all gets compiled, linked and tested well. #ifndef __ATT_H__
1
2784
by: anto.anish | last post by:
Hi , Since, i did not want to write explicit instantiations in Source file of all template methods for various different datatypes that my client might use, i choose to write implementation of template methods along with their declarations in the header file. Well, there are also other files in the project, which include this header file as well, which all gets compiled, linked and tested well. #ifndef __ATT_H__
0
9800
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11181
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10886
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9597
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
7148
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
6014
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4642
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4245
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3252
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.