PC Review


Reply
Thread Tools Rate Thread

Accessing VB .Net Controls from Javascript

 
 
fripper
Guest
Posts: n/a
 
      1st Apr 2004

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


 
Reply With Quote
 
 
 
 
Cor
Guest
Posts: n/a
 
      1st Apr 2004
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
///



 
Reply With Quote
 
Cor
Guest
Posts: n/a
 
      1st Apr 2004
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
///


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Accessing javascript var from C# Gaurav Microsoft C# .NET 3 12th Oct 2009 03:58 PM
Accessing server controls using javascript... Stu Microsoft ASP .NET 2 20th Mar 2006 07:10 PM
Re: Controls accessing other controls of same type? Darren Clark Microsoft ASP .NET 1 3rd May 2004 05:37 AM
Controls accessing other controls of same type? Darren Clark Microsoft ASP .NET 0 3rd May 2004 03:53 AM
Accessing Web Forms Controls with javascript Red Microsoft ASP .NET 2 25th Apr 2004 02:22 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:50 PM.