onLoad Javascript

C

chrispragash

Hello all,

I am trying to hide a panel when my asp.net page first renders - the
objective is to toggle the visibility at the click of a button. I wrote
a javascript (with script like ClientID.style.visibility = "hidden"),
registered this script using Page.RegisterClientScriptBlock, and added
an Attribute to the control (Control.Attributes.Add("onLoad", "Id of
script")). The javascript is not being called at all!. Any ideas would
be of great help.

Regards,
Chris
 
H

Hans Kesting

Hello all,

I am trying to hide a panel when my asp.net page first renders - the
objective is to toggle the visibility at the click of a button. I
wrote a javascript (with script like ClientID.style.visibility =
"hidden"), registered this script using
Page.RegisterClientScriptBlock, and added an Attribute to the control
(Control.Attributes.Add("onLoad", "Id of script")). The javascript is
not being called at all!. Any ideas would be of great help.

Regards,
Chris

When you say "id of script", do you mean just the name of the function,
or even the code that you used registering the script block?
You should use the name of the function, followed by ( ) (that is, a plain function call).
The registration name has no meaning at all, client-side.

You could also use Page.RegisterStartupScript. This code will execute when most of
the page has already been loaded.

What does the generated code look like in the browser (do a "view source"
and search for your code)? You need to include the <script> tags
in the code-block.

Hans Kesting
 
C

chrispragash

Hans,

Thanks for responding. In the attributes, I am actually specifying the
name of the javascript function, I verfied this by executing the
function in onClick and everything works fine. The problem is I want to
execute this when the page loads. And all this code is in a Server
control. Any ideas or suggestions?

Thanks,
Chris
 
H

Hans Kesting

Hans,

Thanks for responding. In the attributes, I am actually specifying the
name of the javascript function, I verfied this by executing the
function in onClick and everything works fine. The problem is I want
to execute this when the page loads. And all this code is in a Server
control. Any ideas or suggestions?

Thanks,
Chris

Executing code in the onLoad of a *page* will work. Be sure to add a ";" after
your call, .Net may append code of it's own.
A *control* is not something that is recognised as a separate entity at the client,
so I don't think it's possible to add an onLoad handler to a *control*.

Hans Kesting
 
B

Bruce Barker

only the <body> tag has an onload event in the browser.

<body onload="myclientscript()">

you could put a runat server and id tag and do the add attribute. as you
just want to change the style, use the RegisterStartupScript (which renders
just before the </form> tag).

-- bruce (sqlwork.com)
 
Joined
Aug 2, 2009
Messages
1
Reaction score
0
scripting...

hi.... am having a problem with javascripting. have this datepicker, want to show in the page that when the date picked is changed, the date in the textbox and the date picked in the end date will automatically changed into the selected start date. already can do this but the thing is still have to press enter. want it in a way that it will just automatically change. how can i do this? is there any chance that i can do this?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top