从后面的 vb.net 代码调用 javascript [英] Call javascript from vb.net code behind

查看:38
本文介绍了从后面的 vb.net 代码调用 javascript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何从后面的代码中调用 javascript 函数?
最流行的响应是ScriptManager.RegisterStartupScript",但是,这在我的情况下不起作用.

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.

我有一个 vb 类正在执行数据库检查以查看记录是否存在.如果存在,则调用 javascript 函数以显示警报(记录存在")

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');"  

如何从我的 vb.net 类调用这个函数?

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

推荐答案

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

你会像上面那样做,你应该用检查数据库记录存在的条件替换DataStore.Record.Exists(theRecord)

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

这篇关于从后面的 vb.net 代码调用 javascript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆