Calling Javascript Function from within VB Procedure?

  • Thread starter Thread starter Martin Feuersteiner
  • Start date Start date
M

Martin Feuersteiner

Dear Group

I'm using VB to write an aspnet application. I would like to call a
javascript function from within a VB Sub or VB Function, is it possible? My
code is something like this:

VB Code:
Public Sub VBProcedure()
..
..
Run some VB Code...
..
..
Now call the javascript function

End Sub
------------------------------------------------------
Javascript:
<HEAD>
<script language=javascript>
<!--
// MyFunction
function myfunction() {
window.open()
}
//-->
</script>
</HEAD>

I tried javascript: myfunction() within the VB procedure. Well, it was just
a blind guess since the 'javascript:' syntax did not produce any errors.
What is 'javascript:' all about? I can't find it documented.

Thanks for your help & efforts!

Martin
 
Hi Martin,

The most simple sample.

\\\
Dim str As String
str = "<script language=javascript> {window.open('http://www.google.com');}
</script>"
RegisterStartupScript("Startup", str)
///

I hope this helps a little bit?

Cor
 
Hi Cor

Thanks for your message.
Well, I'm not exactly sure whether that's the answer to my problem. After
having had a look at the RegisterScript Methods, it seems to me that it is
just a convenient way to inject the Javascript into the page. I can do this
by writing it directly in the HTML view in VS. Or is there a difference.
Once having the Javsscript registered, I still need a HTML button on my page
whick calls the Javascript in the OnClick Event.

However in my case, I'm calling a VB Sub with the OnItemCommand Event of the
Datagrid to look up some data depending on the value choosen nin the
datagrid. So the OnItemCommand for the datagrid is already taken. At the
same time when the OnItemCommand Event fires I also would like to execute a
client-side Javascript function after the data has been looked up.
So I thought I'm calling the Javascript from within the VB Sub in which I
look up the data after completion of look-up.

Any possible way to achive this?

Thanks for your help & efforts!

Kind Regards,

Martin
 
Hi Cor

Thanks for your message.
Well, I'm not exactly sure whether that's the answer to my problem. After
having had a look at the RegisterScript Methods, it seems to me that it is
just a convenient way to inject the Javascript into the page. I can do this
by writing it directly in the HTML view in VS. Or is there a difference.
Once having the Javsscript registered, I still need a HTML button on my page
whick calls the Javascript in the OnClick Event.

However in my case, I'm calling a VB Sub with the OnItemCommand Event of the
Datagrid to look up some data depending on the value choosen nin the
datagrid. So the OnItemCommand for the datagrid is already taken. At the
same time when the OnItemCommand Event fires I also would like to execute a
client-side Javascript function after the data has been looked up.
So I thought I'm calling the Javascript from within the VB Sub in which I
look up the data after completion of look-up.

Any possible way to achive this?

Thanks for your help & efforts!

Kind Regards,

Martin
 
Hi Martin,

I said that was the simplest one. And I have not direct the answer to your
datagrid, but look also look at this sample (you have to find the postback
event from the datagrid, than I think this will work than also).

\\\A webform with an imagebutton and two bitmaps in the solution map
Private Sub Page_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Me.ImageButton1.ImageUrl = "bitmap2.bmp"
Me.ImageButton1.Attributes("onmouseover") = "this.src='bitmap1.bmp';"
Me.ImageButton1.Attributes("onmouseout") = "this.src='bitmap2.bmp';"
Me.ImageButton1.Attributes("onClick") = _
"window.location='mailto:[email protected]?subject=Cor demo&body=I hope this
helps?';"
End Sub
///

I hope this helps a little bit?

Cor
 
Back
Top