473,396 Members | 2,038 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,396 software developers and data experts.

Object not there on load

I have an object surrounded by <div visible=false runat="server"></div>. So
it doesn't show on the page until I set visible=true.

I need to set focus to the object on post back:

if not IsPostBack then
Dim temp as String = "document.forms[0].Password.focus()"
myBody.Attributes.Add("onload",temp)
end if

This code works fine but it does give me a Javascript error symbol at the
bottom of the IE screen which says that it is null or not an object.

How can I set this up so that I don't get the error?

Thanks,

Tom
Mar 1 '07 #1
4 1314
Hi there,

This is because server controls are not rendered if visible property is set
to fale. Please also note client id might be different than just 'Password'
(have a look at generated HTML source in the browser). This is because
asp.net makes it unique by including all ids of the parent server controls.
Anyway, i see you just want to set focis on a give control. ASP.NET has built
in SetFocus function that takes care of rendering javascript for you.

if not IsPostBack then
if myDiv.Visible then
SetFocus(Password)
end if
end if

or

if not IsPostBack then
if myDiv.Visible then
SetFocus(Password.ClientID)
end if
end if

Hope this helps
--
Milosz
"tshad" wrote:
I have an object surrounded by <div visible=false runat="server"></div>. So
it doesn't show on the page until I set visible=true.

I need to set focus to the object on post back:

if not IsPostBack then
Dim temp as String = "document.forms[0].Password.focus()"
myBody.Attributes.Add("onload",temp)
end if

This code works fine but it does give me a Javascript error symbol at the
bottom of the IE screen which says that it is null or not an object.

How can I set this up so that I don't get the error?

Thanks,

Tom
Mar 1 '07 #2
"Milosz Skalecki [MCAD]" <mi*****@DONTLIKESPAMwp.plwrote in message
news:83**********************************@microsof t.com...
Hi there,

This is because server controls are not rendered if visible property is
set
to fale. Please also note client id might be different than just
'Password'
(have a look at generated HTML source in the browser). This is because
asp.net makes it unique by including all ids of the parent server
controls.
This I know.

But if I am not setting it except on Postback - why does it give me an
error. It does work correctly, it just gives me the error at the bottom of
the screen.

How would you deal with this if you were to create the object on the fly
and had to do the same thing. There also wouldn't be an object on the page
until you create it.
Anyway, i see you just want to set focis on a give control. ASP.NET has
built
in SetFocus function that takes care of rendering javascript for you.
I am using Asp.net 1.1 and I don't think that is available until 2.0 (at
least I think that is the case).

Thanks,

Tom
>
if not IsPostBack then
if myDiv.Visible then
SetFocus(Password)
end if
end if

or

if not IsPostBack then
if myDiv.Visible then
SetFocus(Password.ClientID)
end if
end if

Hope this helps
--
Milosz
"tshad" wrote:
>I have an object surrounded by <div visible=false runat="server"></div>.
So
it doesn't show on the page until I set visible=true.

I need to set focus to the object on post back:

if not IsPostBack then
Dim temp as String = "document.forms[0].Password.focus()"
myBody.Attributes.Add("onload",temp)
end if

This code works fine but it does give me a Javascript error symbol at the
bottom of the IE screen which says that it is null or not an object.

How can I set this up so that I don't get the error?

Thanks,

Tom

Mar 1 '07 #3
Good morning,

What do you mean ‘creating dynamically’ – on the server or client side?

1. If you create it on the server side, use Page.SetFocus(control), or
Page.SetFocus(control.ClientID) after control is created
2. Client side,

<script type=”text/javascript”>
var txt = document.getElementById(‘controlId’);
// or document.getElementById(‘<%=serverControl.Client ID %>’); for server
controls
if (txt)
{
txt.focus();
}
</script>

It also might be something different that I cannot see without the code.
Could you paste it please?

--
Milosz
"tshad" wrote:
"Milosz Skalecki [MCAD]" <mi*****@DONTLIKESPAMwp.plwrote in message
news:83**********************************@microsof t.com...
Hi there,

This is because server controls are not rendered if visible property is
set
to fale. Please also note client id might be different than just
'Password'
(have a look at generated HTML source in the browser). This is because
asp.net makes it unique by including all ids of the parent server
controls.

This I know.

But if I am not setting it except on Postback - why does it give me an
error. It does work correctly, it just gives me the error at the bottom of
the screen.

How would you deal with this if you were to create the object on the fly
and had to do the same thing. There also wouldn't be an object on the page
until you create it.
Anyway, i see you just want to set focis on a give control. ASP.NET has
built
in SetFocus function that takes care of rendering javascript for you.

I am using Asp.net 1.1 and I don't think that is available until 2.0 (at
least I think that is the case).

Thanks,

Tom

if not IsPostBack then
if myDiv.Visible then
SetFocus(Password)
end if
end if

or

if not IsPostBack then
if myDiv.Visible then
SetFocus(Password.ClientID)
end if
end if

Hope this helps
--
Milosz
"tshad" wrote:
I have an object surrounded by <div visible=false runat="server"></div>.
So
it doesn't show on the page until I set visible=true.

I need to set focus to the object on post back:

if not IsPostBack then
Dim temp as String = "document.forms[0].Password.focus()"
myBody.Attributes.Add("onload",temp)
end if

This code works fine but it does give me a Javascript error symbol at the
bottom of the IE screen which says that it is null or not an object.

How can I set this up so that I don't get the error?

Thanks,

Tom


Mar 2 '07 #4
"Milosz Skalecki [MCAD]" <mi*****@DONTLIKESPAMwp.plwrote in message
news:97**********************************@microsof t.com...
Good morning,

What do you mean 'creating dynamically' - on the server or client side?

1. If you create it on the server side, use Page.SetFocus(control), or
Page.SetFocus(control.ClientID) after control is created
2. Client side,

<script type="text/javascript">
var txt = document.getElementById('controlId');
// or document.getElementById('<%=serverControl.ClientID %>'); for server
controls
if (txt)
{
txt.focus();
}
</script>

It also might be something different that I cannot see without the code.
Could you paste it please?
Actually, it was going through the code and that was what was causing the
problem. My mistake. I thought the error was happening as the page was
loaded when it saw an object refered to that didn't exist on the page.

Thanks,

Tom
>
--
Milosz
"tshad" wrote:
>"Milosz Skalecki [MCAD]" <mi*****@DONTLIKESPAMwp.plwrote in message
news:83**********************************@microso ft.com...
Hi there,

This is because server controls are not rendered if visible property is
set
to fale. Please also note client id might be different than just
'Password'
(have a look at generated HTML source in the browser). This is because
asp.net makes it unique by including all ids of the parent server
controls.

This I know.

But if I am not setting it except on Postback - why does it give me an
error. It does work correctly, it just gives me the error at the bottom
of
the screen.

How would you deal with this if you were to create the object on the fly
and had to do the same thing. There also wouldn't be an object on the
page
until you create it.
Anyway, i see you just want to set focis on a give control. ASP.NET has
built
in SetFocus function that takes care of rendering javascript for you.

I am using Asp.net 1.1 and I don't think that is available until 2.0 (at
least I think that is the case).

Thanks,

Tom
>
if not IsPostBack then
if myDiv.Visible then
SetFocus(Password)
end if
end if

or

if not IsPostBack then
if myDiv.Visible then
SetFocus(Password.ClientID)
end if
end if

Hope this helps
--
Milosz
"tshad" wrote:

I have an object surrounded by <div visible=false
runat="server"></div>.
So
it doesn't show on the page until I set visible=true.

I need to set focus to the object on post back:

if not IsPostBack then
Dim temp as String = "document.forms[0].Password.focus()"
myBody.Attributes.Add("onload",temp)
end if

This code works fine but it does give me a Javascript error symbol at
the
bottom of the IE screen which says that it is null or not an object.

How can I set this up so that I don't get the error?

Thanks,

Tom



Mar 2 '07 #5

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

Similar topics

2
by: N. Demos | last post by:
I'm having problems with a custom JS object (XMLLoadObject) I designed to load XML and XSL files, perform an XSL transform with them and embed the resultant HTML fragment into the host HTML...
2
by: John Mullin | last post by:
We are having a problem which appears similar to a previous posting: http://groups.google.com/groups?hl=en&lr=&frame=right&th=d97f552e10f8c94c&seekm=OZw33z9EDHA.2312%40TK2MSFTNGP10.phx.gbl#link1 ...
2
by: Giovanni Bassi | last post by:
Hello All, I have encountered a problem. I am using visual inheritance and my base form adds an event handler on Form Load using the AddHandler Keyword. The problem is that if the Event...
1
by: Angus Lepper | last post by:
I'm writing a stock ticker for a stock market simulation, and can load the data into the xmlreader in the first place, but can't figure out how to refresh/update the data in it. Any ideas? Code:...
4
by: marcosnogood | last post by:
Hello, I need to dynamically load an activex object because what object to load is based on certain conditions. Also I need to wait for the object to have initialized before moving on. What I...
2
by: miked | last post by:
I am architecting in a read only class for use in mapping data to a business object. The object makes strong use of nested classes and their ability to access protected fields. The downside is...
13
by: TS | last post by:
Say i have a class car with properties: Color, Make, Model, Year, DriverID And a Driver class with properties: DriverID, Name The driverID PRIVATE property is the id of the driver from say a...
6
by: Peter Richardson | last post by:
Hi, I'm wondering if someone can help me with some design questions I have. I'm trying to create a class in C# to represent my customers. I know how to create teh Customer class and all, but my...
7
by: Steve | last post by:
I am building an object library for tables in a database. What is the best practice for creating objects like this? For example, say I have the following tables in my database: User: - Id -...
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...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
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 projectplanning, coding, testing,...

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.