簡體   English   中英

從文件后面的ASCII代碼調用Aspx Java腳本函數

[英]Call Aspx java script function from ascx code behind file

我在aspx頁面中有一個JavaScript函數,此aspx頁面中有多個ascx控件。

我需要從文件背后的ascx控制代碼之一調用該JavaScript函數。 我嘗試了以下方法,但未按預期工作。 請提出任何建議。

在aspx頁面中:

<script type="text/javascript">
    function Disable() 
    {
        // some code
        // return;
    }

在文件后面的ascx代碼中:

ScriptManager.RegisterClientScriptBlock(Me.Page, Me.GetType(), "Script", "Disable();", True)

有人可以讓我知道如何解決這個問題嗎?

嘗試使用RegisterStartupScript而不是RegisterClientScriptBlock

ScriptManager.RegisterStartupScript(Page, GetType(), "Script", "Disable();", true);

RegisterClientScriptBlock將javascript內容寫在HTML頁面內容的頂部,而RegisterStartupScript將內容寫在底部的內容。 內聯函數'Disable()`可能在調用它的代碼下面,因此在被觸發時找不到。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM