本文介绍了JavaScript的:Alert.Show(消息)从ASP.NET code-背后的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我读这个<一个href=\"http://archive.devnewz.com/devnewz-3-20061129JavaScriptAlertShowmessagefromASPNET$c$cbehind.html\">JavaScript: Alert.Show(消息)从ASP.NET code-背后

我想实现相同。所以,我创建了一个静态类是这样的:

I am trying to implement the same. So I created a static class like this:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Data.SqlClient;
using System.Web;
using System.Text;
using System.Web.UI;

namespace Registration.DataAccess
{
    public static class Repository
    {
        /// <summary> 
        /// Shows a client-side JavaScript alert in the browser. 
        /// </summary> 
        /// <param name="message">The message to appear in the alert.</param> 
        public static void Show(string message) 
            { 
               // Cleans the message to allow single quotation marks 
               string cleanMessage = message.Replace("'", "\'"); 
               string script = "<script type="text/javascript">alert('" + cleanMessage + "');</script>"; 

               // Gets the executing web page 
               Page page = HttpContext.Current.CurrentHandler as Page; 

               // Checks if the handler is a Page and that the script isn't allready on the Page 
               if (page != null && !page.ClientScript.IsClientScriptBlockRegistered("alert")) 
               { 
                 page.ClientScript.RegisterClientScriptBlock(typeof(Alert), "alert", script); 
               } 
            } 
    }
}

在这一行:

string script = "<script type="text/javascript">alert('" + cleanMessage + "');</script>"; 

这是显示我的错误:;预计

和也

page.ClientScript.RegisterClientScriptBlock(typeof(Alert), "alert", script); 

错误:类型或命名空间名称'警报'找不到(是否缺少using指令或程序集引用)

我在做什么错在这里?

What I am doing wrong here?

推荐答案

下面是一个简单的方法:

Here is an easy way:

Response.Write("<script>alert('Hello');</script>");

这篇关于JavaScript的:Alert.Show(消息)从ASP.NET code-背后的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-27 18:52