.net中弹出对话框(在线等) 在js中弹出对话框,在后台代码中弹出,都有哪些方法,怎样用合适,新手等着用 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 jquery插件 或者用後臺代碼拼接一個層 alert啊。在后台也是调用js啊 ClientScript.RegisterStartupScript(this.GetType(), "asd", "<script>alert('提交成功!')</script>"); Response.Write("<script>alert('这是js弹出框!');</script>");ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "click", "alert('这也是弹出框!')", true); ClientScript.RegisterStartupScriptScriptManager.RegisterClientScriptBlock this.RegisterStartupScript("起名字", "<script>alert('弹出内容');</script>"); 如果没用ajax的话 用这个就ok Response.Write("<script>alert('对话框!');</script>"); 慢点看吧,是一个类,里面加密,解密,过滤关键字,谈对话框什么的都有这是我做项目时写的,自己保存,随用随取,using System;using System.Data;using System.Configuration;using System.Web;using System.Web.Security;using System.Web.UI;using System.Web.UI.WebControls;using System.Web.UI.WebControls.WebParts;using System.Web.UI.HtmlControls;using System.Text;using System.Text.RegularExpressions;namespace Website{ /// <summary> /// 页面层(表示层)基类,所有页面继承该页面 /// </summary> public class PageBase : System.Web.UI.Page { public PageBase() { // // TODO: 在此处添加构造函数逻辑 // } #region 客户端脚本(javascript) /// <summary> /// 客户端脚本(javascript)消息框(alert) /// </summary> public void ClientScriptAlert(string message) { message = message.Replace("\"", "\\\"").Replace("\n", "\\\n").Replace("\r", "\\\r"); string jsText = string.Format("alert(\"{0}\");", message); ClientJavaScript(jsText); } /// <summary> /// 客户端脚本(javascript)消息框(alert),并跳转页面 /// </summary> public void ClientScriptAlert(string message, string url) { message = message.Replace("\"", "\\\"").Replace("\n", "\\\n").Replace("\r", "\\\r"); string scriptText = string.Format("alert(\"{0}\");window.location=\"{1}\";", message, url); ClientJavaScript(scriptText); //this.Response.Write(string.Format("<script type=\"text/javascript\" language=\"javascript\">{0}</script>", scriptText)); //this.Response.End(); } /// <summary> /// 客户端脚本(javascript) /// </summary> public void ClientJavaScript(string scriptText) { string scriptKey = "ClientScript"; int index = 1; while (this.ClientScript.IsStartupScriptRegistered(this.GetType(), scriptKey + index.ToString())) { index++; } scriptText = string.Format("<script type=\"text/javascript\" language=\"javascript\">{0}</script>", scriptText); //RegisterStartupScript(scriptKey + index.ToString(), scriptText); this.ClientScript.RegisterStartupScript(this.GetType(), scriptKey + index.ToString(), scriptText); } #endregion /// <summary> /// 截取指定长度字符串,一个中文两个字节 /// </summary> public string SubString(object value, int len) { return SubString(Convert.ToString(value), len); } /// <summary> /// 截取指定长度字符串,一个中文两个字节 /// </summary> public string SubString(string value, int len) { return Common.Common.SubString(value, len); } /// <summary> /// 日期转为指定格式字符串 /// </summary> public string DateTimeToString(object value, string format) { if (value != null && value != DBNull.Value) { try { return Convert.ToDateTime(value).ToString(format); } catch { } } return string.Empty; } /// <summary> /// 对字符串进行 HTML 编码并返回已编码的字符串。 /// </summary> public string HtmlEncode(object value) { if (value == null || value == DBNull.Value) return string.Empty; return HtmlEncode(value.ToString()); } /// <summary> /// 对字符串进行 HTML 编码并返回已编码的字符串。 /// </summary> public string HtmlEncode(string value) { return HttpUtility.HtmlEncode(value); } /// <summary> /// 过滤HTML中jiavascript,iframe,frameset以及事件等脚本 /// </summary> /// <param name="html">脚本代码</param> /// <returns>过滤后得脚本代码</returns> public string FilterScript(string html) { if (string.IsNullOrEmpty(html)) return html; Regex regex = new Regex(@"<script[\s\S]+</script *>", RegexOptions.IgnoreCase); html = regex.Replace(html, ""); //过滤<script></script>标记 Regex regex1 = new Regex(@" href *= *[\s\S]*script *:", RegexOptions.IgnoreCase); html = regex1.Replace(html, ""); //过滤href=javascript: (<A>) 属性 Regex regex2 = new Regex(@" on(mouseover|mouseon|mouseout|click|dblclick|blur|focus|change)*=", RegexOptions.IgnoreCase); html = regex2.Replace(html, " _disibledevent="); //过滤其它控件的on...事件 Regex regex3 = new Regex(@"<iframe[\s\S]+</iframe *>", RegexOptions.IgnoreCase); html = regex3.Replace(html, ""); //过滤iframe Regex regex4 = new Regex(@"<frameset[\s\S]+</frameset *>", RegexOptions.IgnoreCase); html = regex4.Replace(html, ""); //过滤frameset Regex regex5 = new Regex(@"(Javascript|javascript):", RegexOptions.IgnoreCase); html = regex5.Replace(html, ""); //过滤所有javascript Regex regex6 = new Regex(@":*expression", RegexOptions.IgnoreCase); html = regex6.Replace(html, ""); //过滤所有javascript Regex regex7 = new Regex(@"<!--[\s\S]*-->", RegexOptions.IgnoreCase); html = regex7.Replace(html, ""); //过滤所有HTML说明标签 return html; } #region 客户机登录windows用户帐号 /// <summary> /// 客户机登录windows用户帐号 /// </summary> public string GetLoginUserID() { string userName = string.Empty; if (this.Session["_logonName"] != null) { object obj = this.Session["_logonName"]; userName = Convert.ToString(obj); if (!string.IsNullOrEmpty(userName)) { return userName; } } userName = System.Configuration.ConfigurationManager.AppSettings.Get("LogonName"); if (!string.IsNullOrEmpty(userName)) { this.Session["_logonName"] = userName; return userName; } System.Web.UI.Page pageuser = new System.Web.UI.Page(); userName = this.User.Identity.Name.Trim(); if (!string.IsNullOrEmpty(userName)) { string[] temp = userName.Split('\\'); userName = temp[temp.Length - 1]; } if (this != null) { this.Session["_logonName"] = userName; } return userName; } #endregion /// <summary> /// 加密url参数(QueryString) /// </summary> /// <param name="url">不带参数的url</param> /// <param name="parameters">url参数集</param> /// <returns></returns> public string EncryptUrlQueryString(string url, System.Collections.Generic.Dictionary<string, string> parameters) { return url + EncryptUrlQueryString(parameters); } /// <summary> /// 加密url参数(QueryString) /// </summary> /// <param name="url">不带参数的url</param> /// <param name="parameters">url参数集</param> /// <returns></returns> public string EncryptUrlQueryString(System.Collections.Generic.Dictionary<string, string> parameters) { string queryString = ""; foreach (System.Collections.Generic.KeyValuePair<string, string> pair in parameters) { queryString += "&" + this.Server.UrlEncode(pair.Key) + "=" + this.Server.UrlEncode(pair.Value); } queryString = queryString.TrimStart('&'); return "?s=" + this.Server.UrlEncode(Common.Common.EncryptString(queryString)); } /// <summary> /// 解密url参数(QueryString) /// </summary> /// <returns></returns> public System.Collections.Generic.Dictionary<string, string> DecryptUrlQueryString() { System.Collections.Generic.Dictionary<string, string> dir = new System.Collections.Generic.Dictionary<string, string>(); string queryString=Request.QueryString["s"]; if (!string.IsNullOrEmpty(queryString)) { queryString = Common.Common.DecryptString(queryString); string[] str = queryString.Split('&'); for (int i = 0; i < str.Length; i++) { string key = str[i].Substring(0, str[i].IndexOf("=")); string value = str[i].Replace(key + "=", ""); dir.Add(key, value); } } return dir; } }} Asp.net定时执行某个方法? 关于GridView空间的更新问题 怎样在C# 中替换 word 中的标签 大家帮忙看看是不是少了添加某个命名空间? 水晶报表问题? asp.net 与 MySql的连接问题 ff和opera下载地址解析问题. 分享一个方法:在TextBox中光标位置处插入内容(WEB) 求教如何将上传到网页的文件保存在sql数据库里? 为什么ASP.NET的空间,比PHP空间贵? 请教 HTTP 错误 404.17的处理方法 DropDownList事件问题
在后台也是调用js啊
ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "click", "alert('这也是弹出框!')", true);
ScriptManager.RegisterClientScriptBlock
Response.Write("<script>alert('对话框!');</script>");
这是我做项目时写的,自己保存,随用随取,
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;
using System.Text.RegularExpressions;namespace Website
{
/// <summary>
/// 页面层(表示层)基类,所有页面继承该页面
/// </summary>
public class PageBase : System.Web.UI.Page
{
public PageBase()
{
//
// TODO: 在此处添加构造函数逻辑
//
} #region 客户端脚本(javascript)
/// <summary>
/// 客户端脚本(javascript)消息框(alert)
/// </summary>
public void ClientScriptAlert(string message)
{
message = message.Replace("\"", "\\\"").Replace("\n", "\\\n").Replace("\r", "\\\r");
string jsText = string.Format("alert(\"{0}\");", message);
ClientJavaScript(jsText);
} /// <summary>
/// 客户端脚本(javascript)消息框(alert),并跳转页面
/// </summary>
public void ClientScriptAlert(string message, string url)
{
message = message.Replace("\"", "\\\"").Replace("\n", "\\\n").Replace("\r", "\\\r");
string scriptText = string.Format("alert(\"{0}\");window.location=\"{1}\";", message, url);
ClientJavaScript(scriptText);
//this.Response.Write(string.Format("<script type=\"text/javascript\" language=\"javascript\">{0}</script>", scriptText));
//this.Response.End();
} /// <summary>
/// 客户端脚本(javascript)
/// </summary>
public void ClientJavaScript(string scriptText)
{
string scriptKey = "ClientScript";
int index = 1;
while (this.ClientScript.IsStartupScriptRegistered(this.GetType(), scriptKey + index.ToString()))
{
index++;
} scriptText = string.Format("<script type=\"text/javascript\" language=\"javascript\">{0}</script>", scriptText);
//RegisterStartupScript(scriptKey + index.ToString(), scriptText);
this.ClientScript.RegisterStartupScript(this.GetType(), scriptKey + index.ToString(), scriptText);
}
#endregion /// <summary>
/// 截取指定长度字符串,一个中文两个字节
/// </summary>
public string SubString(object value, int len)
{
return SubString(Convert.ToString(value), len);
}
/// <summary>
/// 截取指定长度字符串,一个中文两个字节
/// </summary>
public string SubString(string value, int len)
{
return Common.Common.SubString(value, len);
} /// <summary>
/// 日期转为指定格式字符串
/// </summary>
public string DateTimeToString(object value, string format)
{
if (value != null && value != DBNull.Value)
{
try
{
return Convert.ToDateTime(value).ToString(format);
}
catch { }
}
return string.Empty;
}
/// <summary>
/// 对字符串进行 HTML 编码并返回已编码的字符串。
/// </summary>
public string HtmlEncode(object value)
{
if (value == null || value == DBNull.Value) return string.Empty; return HtmlEncode(value.ToString());
}
/// <summary>
/// 对字符串进行 HTML 编码并返回已编码的字符串。
/// </summary>
public string HtmlEncode(string value)
{
return HttpUtility.HtmlEncode(value);
} /// <summary>
/// 过滤HTML中jiavascript,iframe,frameset以及事件等脚本
/// </summary>
/// <param name="html">脚本代码</param>
/// <returns>过滤后得脚本代码</returns>
public string FilterScript(string html)
{
if (string.IsNullOrEmpty(html)) return html;
Regex regex = new Regex(@"<script[\s\S]+</script *>", RegexOptions.IgnoreCase);
html = regex.Replace(html, ""); //过滤<script></script>标记
Regex regex1 = new Regex(@" href *= *[\s\S]*script *:", RegexOptions.IgnoreCase);
html = regex1.Replace(html, ""); //过滤href=javascript: (<A>) 属性
Regex regex2 = new Regex(@" on(mouseover|mouseon|mouseout|click|dblclick|blur|focus|change)*=", RegexOptions.IgnoreCase);
html = regex2.Replace(html, " _disibledevent="); //过滤其它控件的on...事件
Regex regex3 = new Regex(@"<iframe[\s\S]+</iframe *>", RegexOptions.IgnoreCase);
html = regex3.Replace(html, ""); //过滤iframe
Regex regex4 = new Regex(@"<frameset[\s\S]+</frameset *>", RegexOptions.IgnoreCase);
html = regex4.Replace(html, ""); //过滤frameset
Regex regex5 = new Regex(@"(Javascript|javascript):", RegexOptions.IgnoreCase);
html = regex5.Replace(html, ""); //过滤所有javascript
Regex regex6 = new Regex(@":*expression", RegexOptions.IgnoreCase);
html = regex6.Replace(html, ""); //过滤所有javascript
Regex regex7 = new Regex(@"<!--[\s\S]*-->", RegexOptions.IgnoreCase);
html = regex7.Replace(html, ""); //过滤所有HTML说明标签
return html;
} #region 客户机登录windows用户帐号
/// <summary>
/// 客户机登录windows用户帐号
/// </summary>
public string GetLoginUserID()
{
string userName = string.Empty;
if (this.Session["_logonName"] != null)
{
object obj = this.Session["_logonName"];
userName = Convert.ToString(obj);
if (!string.IsNullOrEmpty(userName))
{
return userName;
}
} userName = System.Configuration.ConfigurationManager.AppSettings.Get("LogonName");
if (!string.IsNullOrEmpty(userName))
{
this.Session["_logonName"] = userName;
return userName;
} System.Web.UI.Page pageuser = new System.Web.UI.Page();
userName = this.User.Identity.Name.Trim();
if (!string.IsNullOrEmpty(userName))
{
string[] temp = userName.Split('\\');
userName = temp[temp.Length - 1];
} if (this != null)
{
this.Session["_logonName"] = userName;
}
return userName;
}
#endregion /// <summary>
/// 加密url参数(QueryString)
/// </summary>
/// <param name="url">不带参数的url</param>
/// <param name="parameters">url参数集</param>
/// <returns></returns>
public string EncryptUrlQueryString(string url, System.Collections.Generic.Dictionary<string, string> parameters)
{
return url + EncryptUrlQueryString(parameters);
} /// <summary>
/// 加密url参数(QueryString)
/// </summary>
/// <param name="url">不带参数的url</param>
/// <param name="parameters">url参数集</param>
/// <returns></returns>
public string EncryptUrlQueryString(System.Collections.Generic.Dictionary<string, string> parameters)
{
string queryString = "";
foreach (System.Collections.Generic.KeyValuePair<string, string> pair in parameters)
{
queryString += "&" + this.Server.UrlEncode(pair.Key) + "=" + this.Server.UrlEncode(pair.Value);
}
queryString = queryString.TrimStart('&'); return "?s=" + this.Server.UrlEncode(Common.Common.EncryptString(queryString));
} /// <summary>
/// 解密url参数(QueryString)
/// </summary>
/// <returns></returns>
public System.Collections.Generic.Dictionary<string, string> DecryptUrlQueryString()
{
System.Collections.Generic.Dictionary<string, string> dir = new System.Collections.Generic.Dictionary<string, string>(); string queryString=Request.QueryString["s"];
if (!string.IsNullOrEmpty(queryString))
{
queryString = Common.Common.DecryptString(queryString);
string[] str = queryString.Split('&');
for (int i = 0; i < str.Length; i++)
{
string key = str[i].Substring(0, str[i].IndexOf("="));
string value = str[i].Replace(key + "=", "");
dir.Add(key, value);
}
}
return dir;
} }
}