none
.net 页面后台调用前台js方法可以走通吗? RRS feed

  • 问题


  •             //  string bbb = "http://www.baidu.com";
                // Response.Write(string.Format("<script type=\"text/javascript\" src=\"http://g.alicdn.com/ilw/ding/0.9.9/scripts/dingtalk.js\" /><script type=\"text/javascript\" src=\"/common.js\" /><script type=\"text/javascript\">dingdingAlertMessage(\"yudingchenggong\",\"titl\"',\"ok\");windows.location.ref({0})</script>", bbb));
                // ClientScript.RegisterStartupScript(this.GetType(), "", "<script>Button1.click();</script>");
                //Button1_Click(null, null);
                // Button1.Click += Button1_Click1;
                // Page.RegisterClientScriptBlock("Button1", "<script>dingdingAlert()</script>");
                // Page.RegisterStartupScript(" ", " <script> document.getElementById( 'Button1').click(); </script> ");
                // Page.RegisterClientScriptBlock("xxx", Button1.OnClientClick);
                //  Button1.Attributes.Add("onclick", "dingdingAlert();");
                // ClientScript.RegisterStartupScript(this.GetType(), "dingdingAlert", "dingdingAlert()", true);
                // Page.ClientScript.RegisterStartupScript(typeof(string), "dingdingAlert", string.Format("<script language='javascript'>alert('啊啊啊啊');</script>"));
                // this.Page.ClientScript.RegisterStartupScript(this.Page.GetType(), 'Ceshi', '<script>Ceshi();</script>', true);

                //'<script>Ceshi();</script>'
                //string sl = "<script src='http://g.alicdn.com/ilw/ding/0.9.9/scripts/dingtalk.js' type='text/javascript'>    dd.device.notification.alert({  message: \"亲爱的\",  title: \"提示\",//可传空 buttonName: \"收到\", onSuccess: function() {//onSuccess将在点击button之后回调 /*回调*/ }, onFail: function(err) { }});</script>";
                //string sl = "<script type='text/javascript'src='common.js' >Ceshi() </script>";
                // Page.ClientScript.RegisterStartupScript(ClientScript.GetType(), "mya",sl,true);
                //Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "", sl, true);
                //this.Page.ClientScript.RegisterStartupScript(this.Page.GetType(), "Ceshi1", sl, true);
                // Page.ClientScript.RegisterStartupScript(ClientScript.GetType(), "Ceshi", sl);
                // ClientScript.RegisterStartupScript(ClientScript.GetType(), "myscript", "<script>dingdingAlert();</script>");
               // Page.RegisterClientScriptBlock("aaa", "<script>javascript:Ceshi()</script>");


    2016年7月25日 4:06

答案

  • 您好,如果你想从后台来调用JS方法,您可以参考一下这个例子。

    <script>
        function myfunction() {
            alert("i'm a js function");
        }
    </script>
    

    <div>
        <asp:Button ID="btncalljsfunction" runat="server" Text="Call JS Function" OnClick="btncalljsfunction_Click" />
    </div>
    

    protected void btncalljsfunction_Click(object sender, EventArgs e)
    {
        ScriptManager.RegisterStartupScript(this, GetType(), "myFunction", "myfunction();", true);
    }
    

    2016年7月27日 7:46
    版主