在页面加载时从codeehind调用内联Javascript

本文关键字:调用 Javascript codeehind 加载 | 更新日期: 2023-09-27 18:27:18

我的asp.net页面上有一个Javascript块:

<script type="text/javascript">
    Sys.debug = true;
    var popup;
    Sys.require(Sys.components.popup, function () {
        popup = Sys.create.popup("#popup", {
            parentElementID: "target",
        });
    });
</script>

如何从C#代码后面调用它?

ClientScript.RegisterStartupScript(GetType(), "key", ???, true);

在页面加载时从codeehind调用内联Javascript

一种调用方法:

Page.ClientScript.RegisterStartupScript(this.GetType(),"key","xyz();",true);将您的JavaScript保留在一个函数中;

您可以在MSDN上找到有关此问题的帮助:http://social.msdn.microsoft.com/Forums/vstudio/en-US/a5f09794-3224-4c9d-8453-688a303a9198/call-javascript-function-from-c-codebehind

试试这个:

ClientScript.RegisterStartupScript(this.GetType(), "sample", "<script 
    type="text/javascript">Sys.debug = true;var popup;Sys.require(Sys.components.popup,
    function () {popup = Sys.create.popup("#popup", {parentElementID: "target",});});
    </script>",false);