静态功能webmethod中的警报 [英] alert in static function webmethod

查看:45
本文介绍了静态功能webmethod中的警报的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好

我想在Web方法的静态功能中显示警报.

这是我的代码.代码已成功编译,但现在显示警报.请帮忙!

Hi to all

i want to show alert in static function in web method.

here is my code. code is compied successfully but it now showing the alert. Please help !

[WebMethod]
    public  static  void insertvalues(string[] valu)
    {
        try
        {
            score = int.Parse(valu[1]) + int.Parse(valu[3]) + int.Parse(valu[4]) + int.Parse(valu[5]) + int.Parse(valu[6]);
            string script ="<script type=\"text/javascript\">"+string.Format("alert(''{0}'');", score)+";</script>";;
          
            
            Page page = HttpContext.Current.CurrentHandler as Page;

            if (page != null && !page.ClientScript.IsClientScriptBlockRegistered("alert"))
            {
                page.ClientScript.RegisterClientScriptBlock(page.GetType(), "alert", script, true);
            }


        }
        catch (Exception ex)
        {

            throw ex;
        }
     
         
    }



[edit]将我的内容视为纯文本..."选项已禁用-OriginalGriff [/edit]



[edit]"Treat my content as plain text..." option disabled - OriginalGriff[/edit]

推荐答案

我不太惊讶-我不会认为您无法通过静态方法显示警报,因为它不知道要使用哪个会话:它是静态的,并且没有会话.
我怀疑正是出于这个原因,HttpContext.Current.CurrentHandler返回null.
I''m not too surprised - I don''t think you can display an alert from a static method, as it doesn''t know which session to use: it''s static, and doesn''t have a Session.
I suspect that HttpContext.Current.CurrentHandler is returning null for just that reason.


这篇关于静态功能webmethod中的警报的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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