Accessing VB .Net Controls from Javascript

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • fripper

    #1

    Accessing VB .Net Controls from Javascript


    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


  • Cor

    #2
    Re: Accessing VB .Net Controls from Javascript

    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.EventArg s) Handles MyBase.Load
    Me.Image1.Heigh t = New Unit(32)
    Me.Image1.Width = New Unit(200)
    Image1.Visible = True
    Dim scriptString As String = "<script language=JavaSc ript>" & _
    "setclock() ; function setclock(){docu ment.images.Ima ge1.src = " & _

    "'http://localhost/WebClock/WebForm2.aspx'; setTimeout('set clock()',1000)} </s
    cript>"
    Page.RegisterSt artupScript("se tclock", scriptString)
    End Sub
    ///
    \\\Form2 needs nothing
    Private Sub Page_Load(ByVal sender As System.Object, _
    ByVal e As System.EventArg s) Handles MyBase.Load
    Response.Cache. SetExpires(Date Time.Now.AddTic ks(500))
    Dim myForeBrush As Brush = Brushes.Black
    Dim myFont As New Font("Times New Roman", 8, FontStyle.Regul ar)
    Dim textHeight As Single
    Dim bm As New Bitmap(120, 20)
    Dim g As Graphics = Graphics.FromIm age(bm)
    g.Clear(Color.W hite)
    Dim textSize As SizeF = g.MeasureString ("now.tostring" , myFont)
    g.DrawString(No w.ToString, myFont, myForeBrush, _
    New RectangleF(0, 0, 120, 20))
    Dim ms As New IO.MemoryStream
    Dim arrImage() As Byte
    bm.Save(ms, Imaging.ImageFo rmat.Bmp)
    arrImage = ms.GetBuffer
    Response.Binary Write(arrImage)
    End Sub
    ///



    Comment

    • Cor

      #3
      Re: Accessing VB .Net Controls from Javascript

      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


      Private Sub Page_Load(ByVal sender As Object, ByVal e _
      As System.EventArg s) Handles MyBase.Load
      Dim str As String = "<script language=javasc ript " & _
      "src='liveclock .js'>show_clock ()</script>"
      Page.RegisterCl ientScriptBlock ("LiveClock" , str)
      Me.Table1.Rows( 0).Cells(0).Tex t = _
      "<script language='javas cript'>new LiveClock();</script>"
      End Sub
      ///


      Comment

      Working...