[英]Call Aspx java script function from ascx code behind file
I have a JavaScript function in aspx page and this aspx page had several ascx control in it. 我在aspx页面中有一个JavaScript函数,此aspx页面中有多个ascx控件。
I need to call that JavaScript function from one of its ascx control code behind file. 我需要从文件背后的ascx控制代码之一调用该JavaScript函数。 I tried below approach but it is not working as expected.
我尝试了以下方法,但未按预期工作。 Any suggestion please.
请提出任何建议。
in aspx page: 在aspx页面中:
<script type="text/javascript">
function Disable()
{
// some code
// return;
}
in ascx code behind file: 在文件后面的ascx代码中:
ScriptManager.RegisterClientScriptBlock(Me.Page, Me.GetType(), "Script", "Disable();", True)
Can someone please let me know how to resolve this? 有人可以让我知道如何解决这个问题吗?
Try RegisterStartupScript
instead of RegisterClientScriptBlock
尝试使用
RegisterStartupScript
而不是RegisterClientScriptBlock
ScriptManager.RegisterStartupScript(Page, GetType(), "Script", "Disable();", true);
RegisterClientScriptBlock writes the javascript content at the top of the HTML page content while RegisterStartupScript writes the content at the bottom. RegisterClientScriptBlock将javascript内容写在HTML页面内容的顶部,而RegisterStartupScript将内容写在底部的内容。 Chances are that your inline function 'Disable()` is below the code calling it, thus it does not found when fired.
内联函数'Disable()`可能在调用它的代码下面,因此在被触发时找不到。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.