JavaScript file

  • Thread starter Thread starter ruca
  • Start date Start date
R

ruca

I have a JS file, where I have show_clock function to call. I calling
her like this<body onload="show_clock()">, but nothing happens. The clock
don't appear.

In your opinion what should I do? Use "RegisterClientScriptBlock" and/or
"RegisterStartupScript".? If yes, how can I use them?
 
I need to look at the documentation, but one of the two runs prior to the
HTML being written out. This is not the one you want to use. The other puts
the script at the end of the load, which is what you will want. I believe
the RegisterClientScriptBlock is the correct one to have it run after the
HTML is written out, but would have to check the docs to see.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

**********************************************************************
Think Outside the Box!
**********************************************************************
 
RegisterClientScriptBlock() puts the script just after the <form> tag on the
page. RegisterStartupScript() puts the script just before the </form> tag in
the page.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.
 
Right.
But I still don't know how and where to use one of them. Where should I call
them?
 
Can you help me, please. I'm a litle urgency on that and I don't know what
to do.

Thanks
Ruca
 
Hi Ruca,

Two samples in one.
Needs a label1 on a page and a HTML textbox with the name HTMLtextbox1

Private Sub Page_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Dim scriptString As String = "<script language=JavaScript>" & _
"function ShowText() {document.Form1.HTMLTextBox1.value " & _
"= 'I hope this helps?'}" & _
"</script>"
Page.RegisterClientScriptBlock("clientScript", scriptString)

Dim str As String = "<script language " & _
"=javascript>alert('I hope this helps a little bit?');</script>"
Page.RegisterStartupScript("Startup", str)
Me.Label1.Text = "Does this works<br>I hope"

End Sub
I hope this helps a little bit?

Cor
 
And it works the same way if I have an external JavaScript file?
If not, how can I work width?

I have an external file (named clock.js), where I have a function that I
have to call (named show_clock()). It works like you say?
I try this, but not work:

Dim str As String = "<script language=javascript
src='Externo\liveclock.js'>show_clock()</script>
Page.RegisterStartupScript("Startup", str)
 
Hi Ruca,

You can try it with this.

Cor

\\\needs a table on your form with one row and one cell
\\\the timeclock javascript needs to be added to the solution explorer
Private Sub Page_Load(ByVal sender As Object, ByVal e _
As System.EventArgs) Handles MyBase.Load
Dim str As String = "<script language=javascript " & _
"src='liveclock.js'>show_clock()</script>"
Page.RegisterClientScriptBlock("LiveClock", str)
Me.Table1.Rows(0).Cells(0).Text = _
"<script language='javascript'>new LiveClock();</script>"
End Sub
///
 
Cor,
Still don't work. Sorry boring you.

I put just like you said and nothing happens(no text, .., nothing else). My
solutions are escaping, I don't know what to do more.
If you have any more ideas, please tell me!!!!!
Thank you very very very very very very .... very much for your help.
 
Hi Ruca,

Did you drag a server side table to your page and made a row and in that an
item.

I did tested it, and it works in this way in an empty project.

Cor
 
For no doubts, I have this:

CODE part (vb.net)
-------------------------------------------------
Dim str As String = "<script language=javascript
src='Externo\liveclock.js'>show_clock()</script>"
Page.RegisterClientScriptBlock("LiveClock", str)
Me.Table1.Rows(0).Cells(0).Text = "<script language='javascript'>new
LiveClock();</script>"
-------------------------------------------------


HMTL part
-------------------------------------------------
<asp:Table id="Table1" runat="server" Width="153" height="25" style="LEFT:
120px; POSITION: absolute; TOP: 120px">
<asp:TableRow>
<asp:TableCell></asp:TableCell>
</asp:TableRow>
</asp:Table>
-------------------------------------------------

Do you see anything wrong???

Thanks again
Ruca
 
Hi Ruca,

I have pasted your code in,

That gives this
The time is: 3:04:35 PM on Monday, 8th March

Where did you put that javascript, that is the only thing that can be
different.
(I placed it now in a directory as with you in the solution explorerer)

I hope we use the same javascript, it starts with this.

"Live Clock" script (3.0)

Cor
 
Thank you, thank you, thank you for the final tip

I'm using an old version of liveclock.js

I update that file and now it's working better than fine.
(yupiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii)

:)


Thanks Cor, for everything....

Ruca
 
Back
Top