473,378 Members | 1,139 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Masterpages and Javascript

dgk
I was working on a simple app and I would use some javascript to set
the focus:

Dim sb As StringBuilder = New StringBuilder
sb.Append("<script language = 'javascript'>")
sb.Append(" document.getElementById('txtWarrant').focus()")
sb.Append("</script>")
ClientScript.RegisterStartupScript(Me.GetType, "focus",
sb.ToString)

Now I've added a Masterpage and the same code generates an error:

Microsoft JScript runtime error: 'document.getElementById(...)' is
null or not an object

which I guess means that the masterpage is causing the script to
execute before txtWarrant is created. Is there a way around this?
Jul 6 '06 #1
3 1118
No, the problem is that the id of the html element no longer is the same
as the id of the server control. When you put server controls in a
container, like a contentplaceholder, there is a prefix added to the id
to ensure that there are no conflicts.

Use the ClientID property of the control to get the id that is created
for the html element.

dgk wrote:
I was working on a simple app and I would use some javascript to set
the focus:

Dim sb As StringBuilder = New StringBuilder
sb.Append("<script language = 'javascript'>")
sb.Append(" document.getElementById('txtWarrant').focus()")
sb.Append("</script>")
ClientScript.RegisterStartupScript(Me.GetType, "focus",
sb.ToString)

Now I've added a Masterpage and the same code generates an error:

Microsoft JScript runtime error: 'document.getElementById(...)' is
null or not an object

which I guess means that the masterpage is causing the script to
execute before txtWarrant is created. Is there a way around this?
Jul 6 '06 #2
dgk
On Thu, 06 Jul 2006 23:25:05 +0200, Göran Andersson <gu***@guffa.com>
wrote:
>No, the problem is that the id of the html element no longer is the same
as the id of the server control. When you put server controls in a
container, like a contentplaceholder, there is a prefix added to the id
to ensure that there are no conflicts.

Use the ClientID property of the control to get the id that is created
for the html element.
Yes, perfect. Thanks.


>dgk wrote:
>I was working on a simple app and I would use some javascript to set
the focus:

Dim sb As StringBuilder = New StringBuilder
sb.Append("<script language = 'javascript'>")
sb.Append(" document.getElementById('txtWarrant').focus()")
sb.Append("</script>")
ClientScript.RegisterStartupScript(Me.GetType, "focus",
sb.ToString)

Now I've added a Masterpage and the same code generates an error:

Microsoft JScript runtime error: 'document.getElementById(...)' is
null or not an object

which I guess means that the masterpage is causing the script to
execute before txtWarrant is created. Is there a way around this?
Jul 7 '06 #3
dgk
On Fri, 07 Jul 2006 08:20:11 -0400, dgk <dg*@somewhere.comwrote:
>On Thu, 06 Jul 2006 23:25:05 +0200, Göran Andersson <gu***@guffa.com>
wrote:
>>No, the problem is that the id of the html element no longer is the same
as the id of the server control. When you put server controls in a
container, like a contentplaceholder, there is a prefix added to the id
to ensure that there are no conflicts.

Use the ClientID property of the control to get the id that is created
for the html element.

Yes, perfect. Thanks.
Actually it looks like Asp.Net v2 has a focus method for the controls
that appears to do the same thing.
Jul 7 '06 #4

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

Similar topics

4
by: Andrew | last post by:
I am trying to use an editable DataGrid inside a "region" using Microsoft MasterPages ASP.NET v1.0 from asp.net. The datagid loads and displays the data, but when you click edit it generates an...
3
by: Lars W. Andersen | last post by:
Hi, I am looking for a good - easy to comprehend little CMS application for my "beginners" asp.net 2.0 site. It must be able to use Access as the database (only a couple of people will be...
1
by: michael.bollhoefer | last post by:
I was running into issues with the images on the page not working under sub folders. If you leave a master file in the root folder and place content pages in the subfolder then when you hit a...
2
by: iturner100 | last post by:
Hi, I've been struggling with this one for a couple of hours without much joy. Basically, I've got a set of nested masterpages (3 as it happens). I'm dynamically generating a new page in code...
5
by: Nick Wouters | last post by:
Dear All In Classic ASP I used CSS for ALL layout. Now in ASP.NET version 2 I am testing out Masterpages as they come in very handy. It seems like it is replacing CSS for layout but what is...
0
by: Mark Rae | last post by:
Hi, Is there anyway to force a master page to retain the name of the form as programmed instead of changing it to aspnetForm? According to all the articles I've found on this so far:...
6
by: =?Utf-8?B?U3RlcGhlbiBIYXRmaWVsZA==?= | last post by:
I have two masterpages in a web application. One is used for the login and logout pages. The other is used for all other pages in the application. The difference between the two masterpages is...
0
by: HockeyFan | last post by:
I've done this many times with average pages, but in a case I have now, I have a master page with some controls on it. Under certain conditions when the user selects certain options, I want to...
8
by: Mort Strom | last post by:
Right now the header of my master page contains all of the CSS styles for all of the pages that might be loaded in my ContentPlaceHolder. The problem is that my <styletag is getting too large to...
2
Frinavale
by: Frinavale | last post by:
JavaScript in ASP.NET Using JavaScript in ASP.NET pages can make your application seem to work faster and prevent unnecessary calls to the server. JavaScript can be used to perform client-side...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.