Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/329.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
Can';不要让Javascript从c#codebehind启动_C#_Javascript_Asp.net - Fatal编程技术网

Can';不要让Javascript从c#codebehind启动

Can';不要让Javascript从c#codebehind启动,c#,javascript,asp.net,C#,Javascript,Asp.net,我在这里和许多其他网站上读过很多帖子,所以我收集了一些关于如何做到这一点的版本。我的问题是我不能让它做任何事情 以下是Javascript,只是一个测试警报: <script type="text/javascript"> function ICDcheck() { alert('Patient has an ineligible diagnosis code!'); } </script>

我在这里和许多其他网站上读过很多帖子,所以我收集了一些关于如何做到这一点的版本。我的问题是我不能让它做任何事情

以下是Javascript,只是一个测试警报:

    <script type="text/javascript">
        function ICDcheck() {
                alert('Patient has an ineligible diagnosis code!');
        }
    </script>
而且

    string jsMethodName = "ICDcheck()";
    ScriptManager.RegisterClientScriptBlock(this, typeof(string), "uniqueKey", jsMethodName, true);
    lblJavaScript.Text = "<script type='text/javascript'>ICDcheck();</script>";
而且

    string jsMethodName = "ICDcheck()";
    ScriptManager.RegisterClientScriptBlock(this, typeof(string), "uniqueKey", jsMethodName, true);
    lblJavaScript.Text = "<script type='text/javascript'>ICDcheck();</script>";
lblJavaScript.Text=“ICDcheck();”;
最后一个引用了位于脚本和asp:ScriptManager块下方的asp:Content顶部的标签

我在按钮点击、页面加载、sqldatasource选择、formview页面索引交换中放置了这些位,并且始终保持不变,什么都没有

一如既往,感谢您的耐心和帮助。我的无知可能会暴露为问题,但我正在学习。

试试看

<button ID="your_btn" onclick="javascript:your_function(); return false;"><asp:literal ID="your_literal" runat="server" /></button>


函数你的函数{
警报(“患者的诊断代码不合格!”);
}
尝试使用:


同时安装并检查是否有任何脚本错误。

试试这个。在您的页面上,有一个按钮:

<asp:Button ID="RunJsButton" runat="server" Text="Button" />
如果这正是您所追求的,那么您可以对其进行一些重构,以实现最佳实践

这应该行得通

string jsToRun = "<script language=javascript>ICDcheck();</script>";

Type csType = this.GetType();

ClientScript.RegisterStartupScript(csType, "Key", jsToRun);
string jsToRun=“ICDcheck();”;
类型csType=this.GetType();
RegisterStartupScript(csType,“Key”,jsToRun);

尝试Page.ClientScript.RegisterStartupScript(GetType(),“MyKey”,“ICDcheck();”,true);同时安装firebug并检查是否存在任何脚本错误。如果带有“uniqueKey”的脚本已注册或未注册,请使用IsClientScriptBlockRegistered方法进行检查。请看更多的是!山姆,这很有效。天哪,我很想知道为什么有这么多的方法来完成同样的事情,为什么有些方法为某些人工作,而不是为其他人工作。或者,这些其他文件是否打算用于我不完全了解的特定情况?无论如何,感谢您抽出时间来帮助我。@R_Scott对我来说,我遇到了同样的问题scriptmanager没有运行。这背后的原因是我的页面有用户控件,而且我记得它没有启动——如果它对你有帮助,我会把它作为答案:)我也会测试一下,希望能更好地理解这些东西。谢谢你的帮助。@R_Scott如果你想变得更有趣,你可以创建一个类似于这两篇文章和文章中的类。我曾经在编写Web表单应用程序时使用过类似的东西。
    protected void Page_Load(object sender, EventArgs e)
    {
        string scriptToRun = @"function ICDcheck() { alert('Patient has an ineligible diagnosis code!');}";

        ClientScript.RegisterClientScriptBlock(this.GetType(), "", scriptToRun, true);
        RunJsButton.OnClientClick = "return ICDcheck();";
    }
string jsToRun = "<script language=javascript>ICDcheck();</script>";

Type csType = this.GetType();

ClientScript.RegisterStartupScript(csType, "Key", jsToRun);