Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Call javascript from vb.net code behind

How can I call a javascript function from code behind?
The most popular response is "ScriptManager.RegisterStartupScript" however, that does not work in my situation.

I have a vb class that is doing a database check to see if a record exists. If exists, then call a javascript function to display an alert("Record exists")

So I am doing something like

Dim strMessage as string = "javascript:RecordExists('Param');"  

How do I call this function from my vb.net class?

like image 819
Troy Avatar asked Oct 06 '11 11:10

Troy


People also ask

How call JavaScript code behind in VB net?

Using RegisterStartupScript will place the call to showDisplay() at the very bottom of your form, so it will be rendered last and your javascript function will have already been rendered and available.

Can I use JavaScript in VB net?

In reality, you don't need to embed any javascript into your vb.net code. Simply include a javascript file into your page and use the jQuery's . on() event handler.


1 Answers

If DataStore.Record.Exists(theRecord) Then

    Dim script As String = "alert('Record exists')"
    If Not Page.ClientScript.IsStartUpScriptRegistered(Me.GetType(), "alertscript") Then
        Page.ClientScript.RegisterStartUpScript(Me.GetType(), "alertscript", script, True)

    End If
End If

you would do it like above, where you should replaceDataStore.Record.Exists(theRecord) with condition that checks database record exists

like image 51
Deeptechtons Avatar answered Sep 21 '22 03:09

Deeptechtons