Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Javascript DIV and visibility style 1

Status
Not open for further replies.

Caradog

Programmer
Jun 28, 2000
73
0
0
GB
I got a weird effect firing off a JS event on a onClick event in vb.net.

I have this line in my html:

<div align="center" id="divPleaseWait" style="VISIBILITY:hidden">Please Wait</div>

Then this in .vb to make it active:

dlMeters.Attributes.Add("onClick", "JavaScript:doPleaseWait();")

The function doPleaseWait does this:

function doPleaseWait(){
document.getElementById('divPleaseWait').style.visibility = 'visible';
}

However on any of the buttons/links/datalists I add this event to, the first click doesn't make the text in div tag appear, however, every click thereafter on the same button/link/datalist works fine.

Whats going on?
 
It will be because you are adding it (I guess) on the click event of a button. For example,

1) You click an .NET server control (a button)
2) The page loads
3) The button event fires and adds the onclick event

When you next click the button, the event exists and therefore fires but the first time you clicked it it didn't exist and so didn't fire. Make sense?

--------------------------------------------------------------------------------------------------------------------------------------------

Need help finding an answer?

Try the search facility ( or read FAQ222-2244 on how to get better results.
 
RIght, that makes sense, so do I need to retgister the script someway before the page loads?
 
Basically if you want an event to fire it has to be added on the Page Load.

There are several ways to do it such as Page.RegisterStartupScript, Page.RegisterClientScriptBlock or even just making sure you add the Attributes on the Page Load itself.

--------------------------------------------------------------------------------------------------------------------------------------------

Need help finding an answer?

Try the search facility ( or read FAQ222-2244 on how to get better results.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top