Accessing VB .Net Controls from Javascript

F

fripper

Suppose I have a textbox that was created in a VB .Net web application in
design mode ... the name of the textbox is txtCount and its text property is
initially set to 10. Now I go into HTML view and want to add some
JavaScript code to initiate a countdown timer that every second decrements
the value in txtCount.text. I know how to handle the timer itself but I do
not know specifically how to access the txtCount textbox so that I can
change its text property to 9 ... then 8 ... etc.

I am beginning to get a handle on VB .Net and JavaScript but I am at a loss
to see how I can reference a .Net object in JavaScript ... and while there
is a wealth of technical help on these systems I don't see any examples of
the sort of thing described in the preceding paragraph
 
C

Cor

Hi Fripper,

A while ago I made this sample. It is really a sample, you should not use it
in a real environment, however it shows some things I think that you are
asking.

I hope this helps?

Cor

\\\Form 1 Needs a imagebox on the page
Private Sub Page_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Me.Image1.Height = New Unit(32)
Me.Image1.Width = New Unit(200)
Image1.Visible = True
Dim scriptString As String = "<script language=JavaScript>" & _
"setclock(); function setclock(){document.images.Image1.src = " & _

"'http://localhost/WebClock/WebForm2.aspx';setTimeout('setclock()',1000)}</s
cript>"
Page.RegisterStartupScript("setclock", scriptString)
End Sub
///
\\\Form2 needs nothing
Private Sub Page_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Response.Cache.SetExpires(DateTime.Now.AddTicks(500))
Dim myForeBrush As Brush = Brushes.Black
Dim myFont As New Font("Times New Roman", 8, FontStyle.Regular)
Dim textHeight As Single
Dim bm As New Bitmap(120, 20)
Dim g As Graphics = Graphics.FromImage(bm)
g.Clear(Color.White)
Dim textSize As SizeF = g.MeasureString("now.tostring", myFont)
g.DrawString(Now.ToString, myFont, myForeBrush, _
New RectangleF(0, 0, 120, 20))
Dim ms As New IO.MemoryStream
Dim arrImage() As Byte
bm.Save(ms, Imaging.ImageFormat.Bmp)
arrImage = ms.GetBuffer
Response.BinaryWrite(arrImage)
End Sub
///
 
C

Cor

Fripper,

However, this is I think a direct the answer on your question.

I hope this helps?

Cor

\\\Needs a download of LiveClock which has to be placed in the application
folder
\\\\and a webform table with 1 row and 1 cell on the form named Table1
http://www.zip.com.au/~astroboy/liveclock/

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
///
 

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

Top