Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/417.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
为什么';调用JavaScript函数吗?_Javascript_C#_Asp.net_C# 4.0_Webforms - Fatal编程技术网

为什么';调用JavaScript函数吗?

为什么';调用JavaScript函数吗?,javascript,c#,asp.net,c#-4.0,webforms,Javascript,C#,Asp.net,C# 4.0,Webforms,我试图从asp.net代码中调用我的JS函数,但它不起作用 protected void btnSavePrint_Click(object sender, EventArgs e) { try { //int FormTesting; Page.ClientScript.RegisterStartupScript( GetType(), "MyKey", "myFunction();",

我试图从asp.net代码中调用我的JS函数,但它不起作用

 protected void btnSavePrint_Click(object sender, EventArgs e) { 
    try
    {
        //int FormTesting;

        Page.ClientScript.RegisterStartupScript(
        GetType(),
        "MyKey",
        "myFunction();",
        true);

        TestFormNo = ClsTender.InsertAppliedWorks(NitNo, WorkNo, out formno, ContractorID, 
                     Cost.ToDecimal(), bp.LoginMainOfficeID, bp.LoginOrganizationID);
    }
还有我的jsb函数,它在.aspx中

<script>
        function myFunction() {
            window.print();
        }
</script>

函数myFunction(){
window.print();
}
试试这个:

ScriptManager.RegisterStartupScript(this, GetType(), "YourTitle", 
        "myFunction();", true);
试试这个:

ScriptManager.RegisterStartupScript(this, GetType(), "YourTitle", 
        "myFunction();", true);

您正在注册单击按钮时的javascript调用,该调用将在下次加载时调用。单击事件背后的代码,而不是在btnSavePrint\中注册对myFunction()的调用。加载页面中btnSavePrint中的绑定事件。还要确保myFunction的定义存在

protected void Page_Load(object sender, EventArgs e)
{
    btnSavePrint.Attributes.Add("onclick", "myFunction();");
}

您正在注册单击按钮时的javascript调用,该调用将在下次加载时调用。单击事件背后的代码,而不是在btnSavePrint\中注册对myFunction()的调用。加载页面中btnSavePrint中的绑定事件。还要确保myFunction的定义存在

protected void Page_Load(object sender, EventArgs e)
{
    btnSavePrint.Attributes.Add("onclick", "myFunction();");
}

试试这个。看看它是否有效。您可能需要导入
System.Web.UI.Control

ScriptManager.RegisterStartupScript(Me.Page, GetType(Page), UniqueID, "myFunction()", True)
但这段代码将只向浏览器注册JavaScript函数。由于JavaScript是客户端语言,因此将使用此代码注册它。同样,您必须使用以下事件调用此函数

 btnSavePrint.Attributes.Add("onclick", "myFunction();");

试试这个。看看它是否有效。您可能需要导入
System.Web.UI.Control

ScriptManager.RegisterStartupScript(Me.Page, GetType(Page), UniqueID, "myFunction()", True)
但这段代码将只向浏览器注册JavaScript函数。由于JavaScript是客户端语言,因此将使用此代码注册它。同样,您必须使用以下事件调用此函数

 btnSavePrint.Attributes.Add("onclick", "myFunction();");