从后面的代码中调用javascript方法 [英] calling javascript method from code behind

查看:77
本文介绍了从后面的代码中调用javascript方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我想在异常被捕获到最后块之后从代码后面调用javascript方法



i want to call javascript method from code behind after exception is caught in finally block
i.e.

try
{
 //my code here
}
catch()
{
 //msg
}
finally
{

// calling javascript method here

}

推荐答案

我做了类似的事情,就是我从后面的代码中调用了JavaScript警报框.也许你也可以做这样的事情

进行检查并根据您的需要进行更改,以实现您想要的目标.

用于ASP.NET网站的类似于MessageBox的Windows窗体 [ ^ ]
I did a similar thing were I call JavaScript alert box from code behind. perhaps you can also do something like this

check out this and make the changes as per your need to achieve what you want to do.

A Windows Form like MessageBox for ASP.NET Website[^]



尝试这样:


try like this:

try
{
    //my code here
}
catch (Exception ee)
{
   // throw ee;
}
finally
{
    ScriptManager.RegisterClientScriptBlock(Page, this.GetType(), "CallJS", "JSFunctionName();", true);
}


您可以尝试例如:
you can try such as :
finally
{
string script = "<script language='javascript'>yourFunction();</script>";
 Page.RegisterClientScriptBlock("xxx", script);
}



并且该功能应位于页面的顶部,例如:



and the function should be in the head section of page such as:

<script type="text/javascript">
        function yourFunction() {
            alert("Hai");
            return;           
        }
    </script>



有关此主题的更多信息,请参考: a> [^ ]



for more on this topic refer:http://www.codedigest.com/Articles/ASPNET/314_Multiple_Ways_to_Call_Javascript_Function_from_CodeBehind_in_ASPNet.aspx[^]


这篇关于从后面的代码中调用javascript方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆