简体   繁体   English

后面的asp.net代码未调用Javascript代码

[英]Javascript code not being called in asp.net code behind

I have a block of code (posted below) where if the first IF clause is satisfied, the app does not call the javascript('MyPortfolioItemExists()') function. 我有一段代码(在下面发布),如果满足第一个IF子句,则应用程序不会调用javascript('MyPortfolioItemExists()')函数。 Instead, it exits the function and goes on to process other code lines. 相反,它退出该函数并继续处理其他代码行。

If drPortfolio.HasRows Then
    Dim p As Page = CType(System.Web.HttpContext.Current.Handler, Page)
    p.ClientScript.RegisterStartupScript(Me.GetType(), "Script", "javascript:'MyPortfolioItemExists()';", True)
    Return ""
    Exit Function
ElseIf drFav.HasRows = False And drPortfolio.HasRows = False Then
    Utils.ExecNonQuery("insert into UserPortfolio values ('" & PortfoName & "','" & PortfoPage & "','" & Username & "')")
    Return GeneratePortfolioContent()
End If

How can I force the javascript function to be executed? 如何强制执行javascript函数?

p.ClientScript.RegisterStartupScript just registers the script to be executed on the client. p.ClientScript.RegisterStartupScript仅注册要在客户端上执行的脚本。 See the documentation for more information on this function. 有关此功能的更多信息,请参见文档

You can't execute Javascript on the server (unless, of course, you are writing the server-side in Javascript which you are not). 您无法在服务器上执行Javascript(当然,除非您正在使用Javascript编写服务器端,否则您不会)。 Figuring out the difference between server side code and client side code is something many beginners have gotten hung up on and WebForms blurs the line even more. 弄清楚服务器端代码和客户端代码之间的区别是许多初学者都垂涎的东西,而WebForms更加模糊了这一行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM