在registerclientscriptblock中调用javascript函数时出错 [英] Error while calling javascript function in registerclientscriptblock

查看:126
本文介绍了在registerclientscriptblock中调用javascript函数时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





当我尝试从RegisterClientScriptblock调用javascript函数时显示错误,例如



代码:

RegisterClientScriptBlock("fn", "<script>getDueDate('" & txtDueDate.Text & "');</script>")







Error: The value of the property 'getDueDate' is null or undefined, not a Function object.







请建议我解决此问题。




Please suggest me in solving this.

推荐答案

试试这个 -

Try this-
RegisterClientScriptBlock(GetType(),"fn", "<script>getDueDate('" & txtDueDate.Text & "');</script>", true)





希望,它有帮助:)



Hope, it helps :)


首先你需要感谢您没有从您的服务器代码调用javascript,所有registerclientscriptblock都会将javascript添加到您正在呈现的页面。为了让你的js工作,你需要在页面上定义一个名为getDueDate的javascript函数,它必须在顶部的某处定义,以便在脚本块之前包含它。查看源代码以查看脚本的添加位置以及定义getDueDate函数的位置并根据需要进行修改。



如果getDueDate是服务器函数,则不会要工作,你只能调用javascript,并且还要记住你是硬编码的函数来传递页面渲染时txtDueDate.Text中的内容。
First off you need to appreciate that you're not calling javascript from your server code, all registerclientscriptblock does is add javascript to the page you are rendering. In order for your js to work you need a javascript function called getDueDate defined on the page and it has to be defined somewhere at the top so that it is included before your script block. View the source to see where your script is being added and where your getDueDate function is defined and amend as needed.

If getDueDate is a server function this isn't going to work, you can only call javascript, and also remember that you are hard-coded the function to pass whatever is in txtDueDate.Text at the time the page is rendered.


这篇关于在registerclientscriptblock中调用javascript函数时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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