How to fire off Java script function from VB code in VB .Net
Hi everyone. I have an input box function written in java. I have a couple of questions.
First, how would I start that function from the middle of a precedure from my visual basic sub routine? I don't want it to always run when this button is clicked. What I'm doing is checking a database for some specific data, if it's not found, the popup box function needs to open up so they can enter a value in.
also, can I pass some value, say a session value from the vb code to the java function?
Lastly, how could I pass the value they entered in back to the vb process that is running.
Following is the java I tried but I don't think it will use the Session variable I'm trying.
Code:
<script language="javascript">
Function (TermID)
var TermID = prompt("Enter Terminal ID for " & Session("st"));
</script>
I know there are buttons out there that I could click and have them enter a value, but like I said I need this to run sometimes, not everytime the submit button is clicked.
Thanks!
Re: How to fire off Java script function from VB code in VB .Net
I'm having a similar problem and I don't see an answer in the post above.
Here's my scenario.....
I have placed the following javascipt in the html side of my aspx page
(hard coded)
<script language="javascript">
function blahblah()
{
alert('Test')
}
</script>
Now let's look at my code behind....
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
If (Session("callscript" = true) Then
' Here I need to be able to call the script that is already hard coded into my page
End If
End Sub
I don't think it's possible but how would you call an existing script in asp.net code ? :afrog:
Re: How to fire off Java script function from VB code in VB .Net
What you'll need to do is write the script into a label control. Because you can't call a script that hasn't been rendered to the HTML page yet..
Make sure the script is in the head. And your label tag in the body...
Then do something like
<script language = "JavaScript">
function sayHello()
{
alert('Hello');
}
</script>
<asp:label id = "lblScript" runat = "server" />
Then in your server-side code...
Sub CallMyScript()
lblScript.Text = "sayHello();"
End Sub