日期:2014-05-18  浏览次数:20490 次

问个小问题
点保存按钮,将数据保存到数据库,在按钮事件的最后提示保存成功,代码如下
Response.Write( " <script> alert( '保存成功 '); </script> ");
会弹出提示框,点提示框里的“确定”,页面上的字体就会变,比如原来设置为
<body   style= "font-size:small; "> ,点确定按钮后字体会变最大。
为什么会出现这种情况?应该怎么解决?

------解决方案--------------------
添加类:
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.IO;
using System.Text;
using System.Text.RegularExpressions;
/// <summary>
/// Base 的摘要说明
/// </summary>
public sealed class BaseHelp
{
public BaseHelp()
{
//
// TODO: 在此处添加构造函数逻辑
//
}
public static bool IsMatch(string input, string patt)
{
return Regex.IsMatch(input, patt, RegexOptions.IgnoreCase);
}
public static void BindImage(Page page, Control unid, string dispid)
{
StringBuilder sb = new StringBuilder();
sb.Append( "function displayLocal(unid,dispid){var k=document.getElementById(unid);var x=document.getElementById(dispid); ");
sb.Append( "if(k && x){x.src=k.value;}} ");
if (!page.ClientScript.IsClientScriptBlockRegistered( "displaylocalimage "))
{
page.ClientScript.RegisterClientScriptBlock(page.GetType(), "displaylocalimage ", sb.ToString(), true);
}


if (unid != null)
{
FileUpload fu = (FileUpload)unid;

fu.Attributes.Add( "onchange ", string.Format( "displayLocal( '{0} ', '{1} '); ", fu.ClientID, dispid));
}
}
public static string getApplicationPath()
{
return VirtualPathUtility.AppendTrailingSlash(HttpContext.Current.Request.ApplicationPath);
}
public static void Alert(string str,Page page)
{
page.ClientScript.RegisterStartupScript(page.GetType(), "alert ", string.Format( "alert(\ "{0}\ ") ", str), true);
}
}

==============================================================================
在页面里:
BaseHelp.Alert( "可以了吗? ",Page);