DotNetNewsgroup.com  
web access to complete list of Microsoft.NET newsgroups
   home   |   control panel login   |   archive  |  
 
  carried group
academic
adonet
aspnet
aspnet.announcements
aspnet.buildingcontrols
aspnet.caching
aspnet.datagridcontrol
aspnet.mobile
aspnet.security
aspnet.webcontrols
aspnet.webservices
assignment_manager
datatools
dotnet.distributed_apps
dotnet.general
dotnet.myservices
dotnet.nternationalization
dotnet.scripting
dotnet.security
dotnet.vjsharp
dotnet.vsa
dotnet.xml
dotnetfaqs
framework
framework.clr
framework.compactframework
framework.component_services
framework.controls
framework.databinding
framework.drawing
framework.enhancements
framework.interop
framework.odbcnet
framework.performance
framework.remoting
framework.sdk
framework.setup
framework.webservices
framework.windowsforms
framework.wmi
frwk.windowsforms.designtime
lang.csharp
lang.jscript
lang.vb
lang.vb.controls
lang.vb.data
lang.vb.upgrade
lang.vc
lang.vc.libraries
  
 
start date: Thu, 16 Aug 2007 17:38:06 -0700,    posted on: microsoft.public.dotnet.framework.aspnet        back       

Thread Index
  1    GaryDean am
          2    Sergey Poberezovskiy
          3    (Steven Cheng[MSFT])
          4    Gigabyteconceptman
          5    George Ter-Saakov


JavaScript in content pages?   
I used to do the following to set the cursor when there was no masterpage in 
use....
<HEAD>
  <title>Login</title>
  <meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
  <meta content="Visual Basic .NET 7.1" name="CODE_LANGUAGE">
  <meta content="JavaScript" name="vs_defaultClientScript">
  <meta content="http://schemas.microsoft.com/intellisense/ie5" 
name="vs_targetSchema">
  <script language="javascript">
  <!--
  function setcursor()
  {
  document.Form1.tbEmail.focus()
  }
  // -->
  </script>
 </HEAD>
 <body onload="setcursor().......

But now with a masterpage there is no body and I can find no place to put my 
onload="setcursor".  Also where does the <script go now?  It doesn't like it 
anyplace I try.

thanks,
Gary
Date:Thu, 16 Aug 2007 17:38:06 -0700   Author:  

RE: JavaScript in content pages?   
1. to set focus to a control in ASP 2.0 you do not need to write your own 
javascript - the framework provides a (Page) method for that -"SetFocus".

2. If you need to include javascript, you can use various methods of 
Page.ClientScript object, such as RegisterStartupScript, 
RegisterClientScriptBlock, RegisterClientScriptInclude, etc

2. If you want to include javascript into your <head>, you could include a 
literal in your page Header (either declaratively in Master page, or 
programmatically in your page), and then set your literal text to the script 
you need, similar to the following:
Literal ltr = new Literal;
ltr.Text = "<script type='text/javascript'>alert('Hello world');</script>";
this.Page.Header.Add(ltr);

3. You can also declaratively add javascript to your content pages:

<asp:Content ID="cnt" ContentPlaceHolderID="plh" Runat="Server">
	<script type="text/javascript" src="scripts/myLinkedScript.js"></script>
	<script type="text/javascript">
<!--
alert('Another hello');
//	-->
	</script>
</asp:Content>


"GaryDean" wrote:


> I used to do the following to set the cursor when there was no masterpage in 
> use....
> <HEAD>
>   <title>Login</title>
>   <meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
>   <meta content="Visual Basic .NET 7.1" name="CODE_LANGUAGE">
>   <meta content="JavaScript" name="vs_defaultClientScript">
>   <meta content="http://schemas.microsoft.com/intellisense/ie5" 
> name="vs_targetSchema">
>   <script language="javascript">
>   <!--
>   function setcursor()
>   {
>   document.Form1.tbEmail.focus()
>   }
>   // -->
>   </script>
>  </HEAD>
>  <body onload="setcursor().......
> 
> But now with a masterpage there is no body and I can find no place to put my 
> onload="setcursor".  Also where does the <script go now?  It doesn't like it 
> anyplace I try.
> 
> thanks,
> Gary 
> 
> 
> 
Date:Thu, 16 Aug 2007 18:38:00 -0700   Author:  

RE: JavaScript in content pages?   
Hi Gary,

From your description, you're wondering how to register some client script 
to manipulate some html input elements on a master-page based ASP.NET web 
page, correct?

For the original script you provided:

===============
 <script language="javascript">
  <!--
  function setcursor()
  {
  document.Form1.tbEmail.focus()
  }
  // -->
  </script>
=================

the limitation here (for master page based one) is that the "tbEmail" is 
hard coded, you can change it to a more flexible one. e.g.


>>>>>>>>>>>>

  function setcursor(elmId)
  {
  document.getElementById(elm).focus();
  }
<<<<<<<<<<<

this function can be defined in master page(or register programmatically in 
content page).

And in the content page (that applies the master page), you can use code to 
register some script block or startup script .e.g


>>>>>>>>>>>>>

string script = @"setcursor('" + TextBox1.ClientID + "');";
        Page.ClientScript.RegisterStartupScript(this.GetType(), 
"setcursor_txt", script, true);
    }
<<<<<<<<<<<<<<<<

#Page.ClientScript Property
http://msdn2.microsoft.com/en-us/library/system.web.ui.page.clientscript.asp
x

#ClientScriptManager.RegisterStartupScript Method
http://msdn2.microsoft.com/en-us/library/system.web.ui.clientscriptmanager.r
egisterstartupscript.aspx

If you have any other ideas or thought on this, please feel free to post 
here.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead

 

==================================================

Get notification to my posts through email? Please refer to 
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

 

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues 
where an initial response from the community or a Microsoft Support 
Engineer within 1 business day is acceptable. Please note that each follow 
up response may take approximately 2 business days as the support 
professional working with you may need further investigation to reach the 
most efficient resolution. The offering is not appropriate for situations 
that require urgent, real-time or phone-based interactions or complex 
project analysis and dump analysis issues. Issues of this nature are best 
handled working with a dedicated Microsoft Support Engineer by contacting 
Microsoft Customer Support Services (CSS) at 
http://msdn.microsoft.com/subscriptions/support/default.aspx.

==================================================
 	

This posting is provided "AS IS" with no warranties, and confers no rights.
Date:Fri, 17 Aug 2007 03:40:46 GMT   Author:  

Re: JavaScript in content pages?   
All the above is great but it does not answer Gary's question about how to inject some stuff into the pages body tag when using masterpages.
Date:Tue, 21 Aug 2007 10:50:22 -0700   Author:  

Re: JavaScript in content pages?   
why do you want that?

if for body.onload event simply has it anywere on a page.
<script>
window.onload=myfunction;
</script>

George.


<Gigabyteconceptman> wrote in message 
news:%23e10$uB5HHA.5796@TK2MSFTNGP05.phx.gbl...

> All the above is great but it does not answer Gary's question about how to 
> inject some stuff into the pages body tag when using masterpages. 
Date:Tue, 21 Aug 2007 14:25:41 -0400   Author:  

Google
 
Web dotnetnewsgroup.com


COPYRIGHT ?2005, EUROFRONT WORLDWIDE LTD., ALL RIGHT RESERVE  |   Contact us