如何从Javascript调用方法后面的代码 [英] How to call a code behind method from Javascript
本文介绍了如何从Javascript调用方法后面的代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
受保护的 Sub Page_Load( ByVal 发件人作为 对象, ByVal e As System.EventArgs)句柄 我 .Load
Ajax.Utility.RegisterTypeForAjax( GetType (WebForm1))
End Sub
< Ajax.AjaxMethod(Ajax.HttpSessionStateRequirement.Read)> _
函数 GetData()作为 String
返回 Hello
结束 功能
< script type < span class =code-keyword> = text / javascript>
function Validate(){
var ObjPriRetVal = WebForm1.GetData()
alert(ObjPriRetVal.value)
}
< / script>
我写了这个并且打电话给javascript函数按钮单击但显示错误webform1未定义
webform1.aspx是包含GetData方法的页面名称
请帮助
决方案
如果这是你的浏览器的JavaScript,你永远也不会调用后面的代码,这是服务器端的代码。您只能通过导航到某个页面或Ajax来发送HTTP请求:
http://en.wikipedia.org/wiki/Ajax_%28programming%29 [ ^ ],
http://api.jquery .com / jquery.ajax [ ^ ]。< br $>
-SA
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Ajax.Utility.RegisterTypeForAjax(GetType(WebForm1))
End Sub
<Ajax.AjaxMethod(Ajax.HttpSessionStateRequirement.Read)> _
Function GetData() As String
Return "Hello"
End Function
<script type="text/javascript>
function Validate() {
var ObjPriRetVal = WebForm1.GetData()
alert(ObjPriRetVal.value)
}
</script>
I have written this and calling a javascript function on button click but it is showing error webform1 is undefined
webform1.aspx is name of page which contain GetData method
please help
解决方案
If this is JavaScript of your browser, you never ever call the code behind, which is the server-side code. You can only send HTTP request, which you can do by navigating to some page or Ajax:
http://en.wikipedia.org/wiki/Ajax_%28programming%29[^],
http://api.jquery.com/jquery.ajax[^].
—SA
这篇关于如何从Javascript调用方法后面的代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文