asp.net常用javascript封装代码

简介: using System;using System.Text;using System.Data;using System.Configuration;using System.Web;using System.
using  System;
using  System.Text;
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;

namespace  JScript
img_405b18b4b6584ae338e0f6ecaf736533.gifimg_1c53668bcee393edac0d7b3b3daff1ae.gif
{
img_2887d91d0594ef8793c1db92b8a1d545.gifimg_7a2b9a960ee9a98bfd25d306d55009f8.gif    
/**//// <summary>
    
/// 提供向页面输出客户端代码实现特殊功能的方法
    
/// </summary>
    
/// <remarks>
    
/// </remarks>


    
public class JScript
img_2887d91d0594ef8793c1db92b8a1d545.gifimg_7a2b9a960ee9a98bfd25d306d55009f8.gif    
{

img_2887d91d0594ef8793c1db92b8a1d545.gifimg_7a2b9a960ee9a98bfd25d306d55009f8.gif        
/**//// <summary>
        
/// 加入收藏夹
        
/// </summary>
        
/// <param name="url">收藏网址</param>
        
/// <param name="urlname">收藏网址提示</param>
        
/// <param name="name">收藏网址名字</param>


        
public static void aa(string url,string urlname,string name) 
img_2887d91d0594ef8793c1db92b8a1d545.gifimg_7a2b9a960ee9a98bfd25d306d55009f8.gif        

        
string js = @"<a href=# onClick=window.external.addFavorite(‘"+url+",‘"+urlname+"‘) target=_self title=‘"+urlname+"‘>"+name+"</a>  ";
            HttpContext.Current.Response.Write(js);
        }



img_2887d91d0594ef8793c1db92b8a1d545.gifimg_7a2b9a960ee9a98bfd25d306d55009f8.gif        
/**//// <summary>
        
/// 加载以后写自己的脚本
        
/// </summary>
        
/// <param name="pages"></param>
        
/// <param name="yourJs"></param>

        public static void ClientWrite(string yourJs)
img_2887d91d0594ef8793c1db92b8a1d545.gifimg_7a2b9a960ee9a98bfd25d306d55009f8.gif        
{
            Page pages;
            pages 
= HttpContext.Current.Handler as System.Web.UI.Page;
            pages.Controls.Add(
new System.Web.UI.LiteralControl("<script language=javascript>" + yourJs + "</script>"));
        }

img_2887d91d0594ef8793c1db92b8a1d545.gifimg_7a2b9a960ee9a98bfd25d306d55009f8.gif        
/**//**/
img_2887d91d0594ef8793c1db92b8a1d545.gifimg_7a2b9a960ee9a98bfd25d306d55009f8.gif        
/**//// <summary>
        
/// 加载以前写自己的脚本
        
/// </summary>
        
/// <param name="pages"></param>
        
/// <param name="yourJs"></param>

        public static void ClientWrite2(string yourJs)
img_2887d91d0594ef8793c1db92b8a1d545.gifimg_7a2b9a960ee9a98bfd25d306d55009f8.gif        
{
            Page pages;
            pages 
= HttpContext.Current.Handler as System.Web.UI.Page;
            pages.Response.Write(
"<script language=javascript>");
            pages.Response.Write(yourJs);
            pages.Response.Write(
" </script>");
        }


img_2887d91d0594ef8793c1db92b8a1d545.gifimg_7a2b9a960ee9a98bfd25d306d55009f8.gif        
/**//**/

img_2887d91d0594ef8793c1db92b8a1d545.gifimg_7a2b9a960ee9a98bfd25d306d55009f8.gif        
/**//**/
img_2887d91d0594ef8793c1db92b8a1d545.gifimg_7a2b9a960ee9a98bfd25d306d55009f8.gif        
/**//// <summary>
        
///  窗体加载以后探出对话框
        
///  </summary>

        public static void Alert(string msg)
img_2887d91d0594ef8793c1db92b8a1d545.gifimg_7a2b9a960ee9a98bfd25d306d55009f8.gif        
{
            Page pages;
            pages 
= HttpContext.Current.Handler as System.Web.UI.Page;
            msg 
= msg.Replace("""");
            msg 
= msg.Replace("\"""");
            msg = msg.Replace("\n"@"\n").Replace("\r"@"\r").Replace("\"", @"\""");

            pages.Controls.Add(
new System.Web.UI.LiteralControl("<script language=javascript>alert(‘" + msg + "‘);</script>"));
        }

img_2887d91d0594ef8793c1db92b8a1d545.gifimg_7a2b9a960ee9a98bfd25d306d55009f8.gif        
/**//**/
img_2887d91d0594ef8793c1db92b8a1d545.gifimg_7a2b9a960ee9a98bfd25d306d55009f8.gif        
/**//// <summary>
        
/// 窗体没有加载的时候如pageload的时候探出对话框
        
/// </summary>

        public static void Alert_none(string msg)
img_2887d91d0594ef8793c1db92b8a1d545.gifimg_7a2b9a960ee9a98bfd25d306d55009f8.gif        
{
            Page pages;
            pages 
= HttpContext.Current.Handler as System.Web.UI.Page;
            msg 
= msg.Replace("""");
            msg 
= msg.Replace("\"""");
            msg = msg.Replace("\n"@"\n").Replace("\r"@"\r").Replace("\"", @"\""");
            string retu = " alert(‘" + msg + "‘);";
            ClientWrite2(retu);
        }

img_2887d91d0594ef8793c1db92b8a1d545.gifimg_7a2b9a960ee9a98bfd25d306d55009f8.gif        
/**//**/
        
public static void AlertAndRedirect(string message, string toURL)
img_2887d91d0594ef8793c1db92b8a1d545.gifimg_7a2b9a960ee9a98bfd25d306d55009f8.gif        
{
            
string js = "<script language=javascript>alert(‘{0}‘);window.location.replace(‘{1}‘)</script>";
            HttpContext.Current.Response.Write(
string.Format(js, message, toURL));
        }


       
img_2887d91d0594ef8793c1db92b8a1d545.gifimg_7a2b9a960ee9a98bfd25d306d55009f8.gif        
/**//// <summary>
        
/// 弹出JavaScript小窗口
        
/// </summary>
        
/// <param name="js">窗口信息</param>

       
        
public static void Alert(object message)
img_2887d91d0594ef8793c1db92b8a1d545.gifimg_7a2b9a960ee9a98bfd25d306d55009f8.gif        
{
            
string js = @"<Script language=‘JavaScript‘>
                    alert(‘{0}‘);  
                  </Script>
";
            HttpContext.Current.Response.Write(
string.Format(js, message.ToString()));
        }


        
public static void RtnRltMsgbox(object message, string strWinCtrl)
img_2887d91d0594ef8793c1db92b8a1d545.gifimg_7a2b9a960ee9a98bfd25d306d55009f8.gif        
{
            
string js = @"<Script language=‘JavaScript‘>
                     strWinCtrl = true;
                     strWinCtrl = if(!confirm(‘
" + message + "‘))return false;</Script>";
            HttpContext.Current.Response.Write(
string.Format(js, message.ToString()));
        }


img_2887d91d0594ef8793c1db92b8a1d545.gifimg_7a2b9a960ee9a98bfd25d306d55009f8.gif        
/**//// <summary>
        
/// 回到历史页面
        
/// </summary>
        
/// <param name="value">-1/1</param>

        public static void GoHistory(int value)
img_2887d91d0594ef8793c1db92b8a1d545.gifimg_7a2b9a960ee9a98bfd25d306d55009f8.gif        
{
            
string js = @"<Script language=‘JavaScript‘>
                    history.go({0});  
                  </Script>
";
            HttpContext.Current.Response.Write(
string.Format(js, value));
        }


img_2887d91d0594ef8793c1db92b8a1d545.gifimg_7a2b9a960ee9a98bfd25d306d55009f8.gif        
/**//// <summary>
        
/// 关闭当前窗口
        
/// </summary>

        public static void CloseWindow()
img_2887d91d0594ef8793c1db92b8a1d545.gifimg_7a2b9a960ee9a98bfd25d306d55009f8.gif        
{
            
string js = @"<Script language=‘JavaScript‘>
                    window.close();  
                  </Script>
";
            HttpContext.Current.Response.Write(js);
            HttpContext.Current.Response.End();
        }


img_2887d91d0594ef8793c1db92b8a1d545.gifimg_7a2b9a960ee9a98bfd25d306d55009f8.gif        
/**//// <summary>
        
/// 刷新本页
        
/// </summary>

        public static void Refreshself()
img_2887d91d0594ef8793c1db92b8a1d545.gifimg_7a2b9a960ee9a98bfd25d306d55009f8.gif        
{
            
string js = @"<Script language=‘JavaScript‘>
                    window.location=window.location.href;
                  </Script>
";
            HttpContext.Current.Response.Write(js);
        }

img_2887d91d0594ef8793c1db92b8a1d545.gifimg_7a2b9a960ee9a98bfd25d306d55009f8.gif        
/**//// <summary>
        
/// 刷新父窗口
        
/// </summary>

        public static void RefreshParent(string parurl)
img_2887d91d0594ef8793c1db92b8a1d545.gifimg_7a2b9a960ee9a98bfd25d306d55009f8.gif        
{
            
string js = @"<Script language=‘JavaScript‘>
                  window.opener.location.reload(‘
" + parurl + "‘)</Script>";
            HttpContext.Current.Response.Write(js);
        }

img_2887d91d0594ef8793c1db92b8a1d545.gifimg_7a2b9a960ee9a98bfd25d306d55009f8.gif        
/**//// <summary>
        
/// 刷新父框架
        
/// </summary>

        public static void RefreshParentifarme(string url)
img_2887d91d0594ef8793c1db92b8a1d545.gifimg_7a2b9a960ee9a98bfd25d306d55009f8.gif        
{
            
string js = @"<Script language=‘JavaScript‘>
                    window.parent.location.reload(‘
"+url+"‘)</Script>";
            HttpContext.Current.Response.Write(js);
        }


img_2887d91d0594ef8793c1db92b8a1d545.gifimg_7a2b9a960ee9a98bfd25d306d55009f8.gif        
/**//// <summary>
        
/// 格式化为JS可解释的字符串
        
/// </summary>
        
/// <param name="s"></param>
        
/// <returns></returns>

        public static string JSStringFormat(string s)
img_2887d91d0594ef8793c1db92b8a1d545.gifimg_7a2b9a960ee9a98bfd25d306d55009f8.gif        
{
            
return s.Replace("\r""\\r").Replace("\n""\\n").Replace("""\\‘").Replace("\"""\\\"");
        }


img_2887d91d0594ef8793c1db92b8a1d545.gifimg_7a2b9a960ee9a98bfd25d306d55009f8.gif        
/**//// <summary>
        
/// 刷新打开窗口
        
/// </summary>

        public static void RefreshOpener()
img_2887d91d0594ef8793c1db92b8a1d545.gifimg_7a2b9a960ee9a98bfd25d306d55009f8.gif        
{
            
string js = @"<Script language=‘JavaScript‘>
                    opener.location.reload();
                  </Script>
";
            HttpContext.Current.Response.Write(js);
        }



img_2887d91d0594ef8793c1db92b8a1d545.gifimg_7a2b9a960ee9a98bfd25d306d55009f8.gif        
/**//// <summary>
        
/// 打开小窗体
        
/// </summary>
        
/// <param name="url"></param>
        
/// <param name="width"></param>
        
/// <param name="height"></param>
        
/// <param name="top"></param>
        
/// <param name="left"></param>

        public static void OpenLittleWindow(string url, int width, int height, int top, int left)
img_2887d91d0594ef8793c1db92b8a1d545.gifimg_7a2b9a960ee9a98bfd25d306d55009f8.gif        
{
            
string str,js;
            str 
= "var popup;popup=window.open(‘{url}‘,null,‘scrollbars=yes,status=no,width={width},height={height},top={top},left={left}‘);popup.opener=self.opener;self.close();";
            str 
= str.Replace("{width}", width.ToString());
            str 
= str.Replace("{height}", height.ToString());
            str 
= str.Replace("{top}", top.ToString());
            str 
= str.Replace("{left}", left.ToString());
            str 
= str.Replace("{url}", url);
            js 
= @"<Script language=‘JavaScript‘>"+str+" </Script>";
            HttpContext.Current.Response.Write(js);
        }


img_2887d91d0594ef8793c1db92b8a1d545.gifimg_7a2b9a960ee9a98bfd25d306d55009f8.gif        
/**//**/

img_2887d91d0594ef8793c1db92b8a1d545.gifimg_7a2b9a960ee9a98bfd25d306d55009f8.gif        
/**//// <summary>
        
/// 打开窗口
        
/// </summary>
        
/// <param name="url"></param>

        public static void OpenWebForm(string url)
img_2887d91d0594ef8793c1db92b8a1d545.gifimg_7a2b9a960ee9a98bfd25d306d55009f8.gif        
{
img_2887d91d0594ef8793c1db92b8a1d545.gifimg_7a2b9a960ee9a98bfd25d306d55009f8.gif            
/**//*…………………………………………………………………………………………*/
img_2887d91d0594ef8793c1db92b8a1d545.gifimg_7a2b9a960ee9a98bfd25d306d55009f8.gif            
/**//*修改目的:    新开页面去掉ie的菜单。。。                        */

            
string js = @"<Script language=‘JavaScript‘>
            //window.open(‘
" + url + @"‘);
            window.open(‘
" + url + @"‘,‘‘,‘height=0,width=0,top=0,left=0,location=no,menubar=no,resizable=yes,scrollbars=yes,status=yes,titlebar=no,toolbar=no,directories=no‘);
            </Script>
";
img_2887d91d0594ef8793c1db92b8a1d545.gifimg_7a2b9a960ee9a98bfd25d306d55009f8.gif            
/**//*结束*/
img_2887d91d0594ef8793c1db92b8a1d545.gifimg_7a2b9a960ee9a98bfd25d306d55009f8.gif            
/**//*…………………………………………………………………………………………*/


            HttpContext.Current.Response.Write(js);
        }

        
public static void OpenWebForm(string url, string name, string future)
img_2887d91d0594ef8793c1db92b8a1d545.gifimg_7a2b9a960ee9a98bfd25d306d55009f8.gif        
{
            
string js = @"<Script language=‘JavaScript‘>
                     window.open(‘
" + url + @"‘,‘" + name + @"‘,‘" + future + @"‘)
                  </Script>
";
            HttpContext.Current.Response.Write(js);
        }

        
public static void OpenWebForm(string url, string formName)
img_2887d91d0594ef8793c1db92b8a1d545.gifimg_7a2b9a960ee9a98bfd25d306d55009f8.gif        
{
img_2887d91d0594ef8793c1db92b8a1d545.gifimg_7a2b9a960ee9a98bfd25d306d55009f8.gif            
/**//*…………………………………………………………………………………………*/
img_2887d91d0594ef8793c1db92b8a1d545.gifimg_7a2b9a960ee9a98bfd25d306d55009f8.gif            
/**//*修改目的:    新开页面去掉ie的菜单。。。                        */
img_2887d91d0594ef8793c1db92b8a1d545.gifimg_7a2b9a960ee9a98bfd25d306d55009f8.gif            
/**//*注释内容:                                */
img_2887d91d0594ef8793c1db92b8a1d545.gifimg_7a2b9a960ee9a98bfd25d306d55009f8.gif            
/**//*开始*/
            
string js = @"<Script language=‘JavaScript‘>
            window.open(‘
" + url + @"‘,‘" + formName + @"‘,‘height=0,width=0,top=0,left=0,location=no,menubar=no,resizable=yes,scrollbars=yes,status=yes,titlebar=no,toolbar=no,directories=no‘);
            </Script>
";
img_2887d91d0594ef8793c1db92b8a1d545.gifimg_7a2b9a960ee9a98bfd25d306d55009f8.gif            
/**//*结束*/
img_2887d91d0594ef8793c1db92b8a1d545.gifimg_7a2b9a960ee9a98bfd25d306d55009f8.gif            
/**//*…………………………………………………………………………………………*/

            HttpContext.Current.Response.Write(js);
        }


img_2887d91d0594ef8793c1db92b8a1d545.gifimg_7a2b9a960ee9a98bfd25d306d55009f8.gif        
/**//// <summary>        
        
/// 函数名:OpenWebForm    
        
/// 功能描述:打开WEB窗口    
        
/// </summary>
        
/// <param name="url">WEB窗口</param>
        
/// <param name="isFullScreen">是否全屏幕</param>

        public static void OpenWebForm(string url, bool isFullScreen)
img_2887d91d0594ef8793c1db92b8a1d545.gifimg_7a2b9a960ee9a98bfd25d306d55009f8.gif        
{
            
string js = @"<Script language=‘JavaScript‘>";
            
if (isFullScreen)
img_2887d91d0594ef8793c1db92b8a1d545.gifimg_7a2b9a960ee9a98bfd25d306d55009f8.gif            
{
                js 
+= "var iWidth = 0;";
                js 
+= "var iHeight = 0;";
                js 
+= "iWidth=window.screen.availWidth-10;";
                js 
+= "iHeight=window.screen.availHeight-50;";
                js 
+= "var szFeatures =‘width=‘ + iWidth + ‘,height=‘ + iHeight + ‘,top=0,left=0,location=no,menubar=no,resizable=yes,scrollbars=yes,status=yes,titlebar=no,toolbar=no,directories=no‘;";
                js 
+= "window.open(‘" + url + @"‘,‘‘,szFeatures);";
            }

            
else
img_2887d91d0594ef8793c1db92b8a1d545.gifimg_7a2b9a960ee9a98bfd25d306d55009f8.gif            
{
                js 
+= "window.open(‘" + url + @"‘,‘‘,‘height=0,width=0,top=0,left=0,location=no,menubar=no,resizable=yes,scrollbars=yes,status=yes,titlebar=no,toolbar=no,directories=no‘);";
            }

            js 
+= "</Script>";
            HttpContext.Current.Response.Write(js);
        }


img_2887d91d0594ef8793c1db92b8a1d545.gifimg_7a2b9a960ee9a98bfd25d306d55009f8.gif        
/**//// <summary>
        
/// 转向Url制定的页面
        
/// </summary>
        
/// <param name="url"></param>

        public static void JavaScriptLocationHref(string url)
img_2887d91d0594ef8793c1db92b8a1d545.gifimg_7a2b9a960ee9a98bfd25d306d55009f8.gif        
{
            
string js = @"<Script language=‘JavaScript‘>
                    window.location.replace(‘{0}‘);
                  </Script>
";
            js 
= string.Format(js, url);
            HttpContext.Current.Response.Write(js);
        }


img_2887d91d0594ef8793c1db92b8a1d545.gifimg_7a2b9a960ee9a98bfd25d306d55009f8.gif        
/**//// <summary>
        
/// 指定的框架页面转换
        
/// </summary>
        
/// <param name="FrameName"></param>
        
/// <param name="url"></param>

        public static void JavaScriptFrameHref(string FrameName, string url)
img_2887d91d0594ef8793c1db92b8a1d545.gifimg_7a2b9a960ee9a98bfd25d306d55009f8.gif        
{
            
string js = @"<Script language=‘JavaScript‘>
                    
                    @obj.location.replace(""{0}"");
                  </Script>
";
            js 
= js.Replace("@obj", FrameName);
            js 
= string.Format(js, url);
            HttpContext.Current.Response.Write(js);
        }


img_2887d91d0594ef8793c1db92b8a1d545.gifimg_7a2b9a960ee9a98bfd25d306d55009f8.gif        
/**//// <summary>
        
///重置页面
        
/// </summary>

        public static void JavaScriptResetPage(string strRows)
img_2887d91d0594ef8793c1db92b8a1d545.gifimg_7a2b9a960ee9a98bfd25d306d55009f8.gif        
{
            
string js = @"<Script language=‘JavaScript‘>
                    window.parent.CenterFrame.rows=‘
" + strRows + "‘;</Script>";
            HttpContext.Current.Response.Write(js);
        }


img_2887d91d0594ef8793c1db92b8a1d545.gifimg_7a2b9a960ee9a98bfd25d306d55009f8.gif        
/**//// <summary>
        
/// 函数名:JavaScriptSetCookie
        
/// 功能描述:客户端方法设置Cookie
        
/// </summary>
        
/// <param name="strName">Cookie名</param>
        
/// <param name="strValue">Cookie值</param>

        public static void JavaScriptSetCookie(string strName, string strValue)
img_2887d91d0594ef8793c1db92b8a1d545.gifimg_7a2b9a960ee9a98bfd25d306d55009f8.gif        
{
            
string js = @"<script language=Javascript>
            var the_cookie = ‘
" + strName + "=" + strValue + @"
            var dateexpire = ‘Tuesday, 01-Dec-2020 12:00:00 GMT‘;
            //document.cookie = the_cookie;//写入Cookie<BR>} <BR>
            document.cookie = the_cookie + ‘; expires=‘+dateexpire;            
            </script>
";
            HttpContext.Current.Response.Write(js);
        }


img_2887d91d0594ef8793c1db92b8a1d545.gifimg_7a2b9a960ee9a98bfd25d306d55009f8.gif        
/**//// <summary>        
        
/// 函数名:GotoParentWindow    
        
/// 功能描述:返回父窗口    
        
/// </summary>
        
/// <param name="parentWindowUrl">父窗口</param>        

        public static void GotoParentWindow(string parentWindowUrl)
img_2887d91d0594ef8793c1db92b8a1d545.gifimg_7a2b9a960ee9a98bfd25d306d55009f8.gif        
{
            
string js = @"<Script language=‘JavaScript‘>
                    this.parent.location.replace(‘
" + parentWindowUrl + "‘);</Script>";
            HttpContext.Current.Response.Write(js);
        }


img_2887d91d0594ef8793c1db92b8a1d545.gifimg_7a2b9a960ee9a98bfd25d306d55009f8.gif        
/**//// <summary>        
        
/// 函数名:ReplaceParentWindow    
        
/// 功能描述:替换父窗口    
        
/// </summary>
        
/// <param name="parentWindowUrl">父窗口</param>
        
/// <param name="caption">窗口提示</param>
        
/// <param name="future">窗口特征参数</param>

        public static void ReplaceParentWindow(string parentWindowUrl, string caption, string future)
img_2887d91d0594ef8793c1db92b8a1d545.gifimg_7a2b9a960ee9a98bfd25d306d55009f8.gif        
{
            
string js = "";
            
if (future != null && future.Trim() != "")
img_2887d91d0594ef8793c1db92b8a1d545.gifimg_7a2b9a960ee9a98bfd25d306d55009f8.gif            
{
                js 
= @"<script language=javascript>this.parent.location.replace(‘" + parentWindowUrl + "‘,‘" + caption + "‘,‘" + future + "‘);</script>";
            }

            
else
img_2887d91d0594ef8793c1db92b8a1d545.gifimg_7a2b9a960ee9a98bfd25d306d55009f8.gif            
{
                js 
= @"<script language=javascript>var iWidth = 0 ;var iHeight = 0 ;iWidth=window.screen.availWidth-10;iHeight=window.screen.availHeight-50;
                            var szFeatures = ‘dialogWidth:‘+iWidth+‘;dialogHeight:‘+iHeight+‘;dialogLeft:0px;dialogTop:0px;center:yes;help=no;resizable:on;status:on;scroll=yes‘;this.parent.location.replace(‘
" + parentWindowUrl + "‘,‘" + caption + "‘,szFeatures);</script>";
            }


            HttpContext.Current.Response.Write(js);
        }


img_2887d91d0594ef8793c1db92b8a1d545.gifimg_7a2b9a960ee9a98bfd25d306d55009f8.gif        
/**//// <summary>        
        
/// 函数名:ReplaceOpenerWindow    
        
/// 功能描述:替换当前窗体的打开窗口    
        
/// </summary>
        
/// <param name="openerWindowUrl">当前窗体的打开窗口</param>        

        public static void ReplaceOpenerWindow(string openerWindowUrl)
img_2887d91d0594ef8793c1db92b8a1d545.gifimg_7a2b9a960ee9a98bfd25d306d55009f8.gif        
{
            
string js = @"<Script language=‘JavaScript‘>
                    window.opener.location.replace(‘
" + openerWindowUrl + "‘);</Script>";
            HttpContext.Current.Response.Write(js);
        }


img_2887d91d0594ef8793c1db92b8a1d545.gifimg_7a2b9a960ee9a98bfd25d306d55009f8.gif        
/**//// <summary>        
        
/// 函数名:ReplaceOpenerParentWindow    
        
/// 功能描述:替换当前窗体的打开窗口的父窗口    
        
/// </summary>
        
/// <param name="openerWindowUrl">当前窗体的打开窗口的父窗口</param>        

        public static void ReplaceOpenerParentFrame(string frameName, string frameWindowUrl)
img_2887d91d0594ef8793c1db92b8a1d545.gifimg_7a2b9a960ee9a98bfd25d306d55009f8.gif        
{
            
string js = @"<Script language=‘JavaScript‘>
                    window.opener.parent.
" + frameName + ".location.replace(‘" + frameWindowUrl + "‘);</Script>";
            HttpContext.Current.Response.Write(js);
        }


img_2887d91d0594ef8793c1db92b8a1d545.gifimg_7a2b9a960ee9a98bfd25d306d55009f8.gif        
/**//// <summary>        
        
/// 函数名:ReplaceOpenerParentWindow    
        
/// 功能描述:替换当前窗体的打开窗口的父窗口    
        
/// </summary>
        
/// <param name="openerWindowUrl">当前窗体的打开窗口的父窗口</param>        

        public static void ReplaceOpenerParentWindow(string openerParentWindowUrl)
img_2887d91d0594ef8793c1db92b8a1d545.gifimg_7a2b9a960ee9a98bfd25d306d55009f8.gif        
{
            
string js = @"<Script language=‘JavaScript‘>
                    window.opener.parent.location.replace(‘
" + openerParentWindowUrl + "‘);</Script>";
            HttpContext.Current.Response.Write(js);
        }


img_2887d91d0594ef8793c1db92b8a1d545.gifimg_7a2b9a960ee9a98bfd25d306d55009f8.gif        
/**//// <summary>        
        
/// 函数名:CloseParentWindow    
        
/// 功能描述:关闭窗口    
        
/// </summary>

        public static void CloseParentWindow()
img_2887d91d0594ef8793c1db92b8a1d545.gifimg_7a2b9a960ee9a98bfd25d306d55009f8.gif        
{
            
string js = @"<Script language=‘JavaScript‘>
                    window.parent.close();  
                  </Script>
";
            HttpContext.Current.Response.Write(js);
        }


        
public static void CloseOpenerWindow()
img_2887d91d0594ef8793c1db92b8a1d545.gifimg_7a2b9a960ee9a98bfd25d306d55009f8.gif        
{
            
string js = @"<Script language=‘JavaScript‘>
                    window.opener.close();  
                  </Script>
";
            HttpContext.Current.Response.Write(js);
        }


img_2887d91d0594ef8793c1db92b8a1d545.gifimg_7a2b9a960ee9a98bfd25d306d55009f8.gif        
/**//// <summary>
        
/// 函数名:ShowModalDialogJavascript    
        
/// 功能描述:返回打开模式窗口的脚本    
        
/// </summary>
        
/// <param name="webFormUrl"></param>
        
/// <returns></returns>

        public static string ShowModalDialogJavascript(string webFormUrl)
img_2887d91d0594ef8793c1db92b8a1d545.gifimg_7a2b9a960ee9a98bfd25d306d55009f8.gif        
{
            
string js = @"<script language=javascript>
                            var iWidth = 0 ;
                            var iHeight = 0 ;
                            iWidth=window.screen.availWidth-10;
                            iHeight=window.screen.availHeight-50;
                            var szFeatures = ‘dialogWidth:‘+iWidth+‘;dialogHeight:‘+iHeight+‘;dialogLeft:0px;dialogTop:0px;center:yes;help=no;resizable:on;status:on;scroll=yes‘;
                            showModalDialog(‘
" + webFormUrl + "‘,‘‘,szFeatures);</script>";
            
return js;
        }


        
public static string ShowModalDialogJavascript(string webFormUrl, string features)
img_2887d91d0594ef8793c1db92b8a1d545.gifimg_7a2b9a960ee9a98bfd25d306d55009f8.gif        
{
            
string js = @"<script language=javascript>                            
                            showModalDialog(‘
" + webFormUrl + "‘,‘‘,‘" + features + "‘);</script>";
            
return js;
        }


img_2887d91d0594ef8793c1db92b8a1d545.gifimg_7a2b9a960ee9a98bfd25d306d55009f8.gif        
/**//// <summary>
        
/// 函数名:ShowModalDialogWindow    
        
/// 功能描述:打开模式窗口    
        
/// </summary>
        
/// <param name="webFormUrl"></param>
        
/// <returns></returns>

        public static void ShowModalDialogWindow(string webFormUrl)
img_2887d91d0594ef8793c1db92b8a1d545.gifimg_7a2b9a960ee9a98bfd25d306d55009f8.gif        
{
            
string js = ShowModalDialogJavascript(webFormUrl);
            HttpContext.Current.Response.Write(js);
        }


        
public static void ShowModalDialogWindow(string webFormUrl, string features)
img_2887d91d0594ef8793c1db92b8a1d545.gifimg_7a2b9a960ee9a98bfd25d306d55009f8.gif        
{
            
string js = ShowModalDialogJavascript(webFormUrl, features);
            HttpContext.Current.Response.Write(js);
        }

        
public static void ShowModalDialogWindow(string webFormUrl, int width, int height, int top, int left)
img_2887d91d0594ef8793c1db92b8a1d545.gifimg_7a2b9a960ee9a98bfd25d306d55009f8.gif        
{
            
string features = "dialogWidth:" + width.ToString() + "px"
                
+ ";dialogHeight:" + height.ToString() + "px"
                
+ ";dialogLeft:" + left.ToString() + "px"
                
+ ";dialogTop:" + top.ToString() + "px"
                
+ ";center:yes;help=no;resizable:no;status:no;scroll=no";
            ShowModalDialogWindow(webFormUrl, features);
        }


        
public static void SetHtmlElementValue(string formName, string elementName, string elementValue)
img_2887d91d0594ef8793c1db92b8a1d545.gifimg_7a2b9a960ee9a98bfd25d306d55009f8.gif        
{
            
string js = @"<Script language=‘JavaScript‘>if(document." + formName + "." + elementName + "!=null){document." + formName + "." + elementName + ".value =" + elementValue + ";}</Script>";
            HttpContext.Current.Response.Write(js);
        }

    
img_2887d91d0594ef8793c1db92b8a1d545.gifimg_7a2b9a960ee9a98bfd25d306d55009f8.gif     
/**//**/
img_2887d91d0594ef8793c1db92b8a1d545.gifimg_7a2b9a960ee9a98bfd25d306d55009f8.gif    
/**//// <summary>
    
/// 回车-〉tab
    
/// </summary>
    
/// <param name="page"></param>

    public static void ToTab()
img_2887d91d0594ef8793c1db92b8a1d545.gifimg_7a2b9a960ee9a98bfd25d306d55009f8.gif    
{
        Page page;
        page 
= HttpContext.Current.Handler as System.Web.UI.Page;
        System.Text.StringBuilder scriptFunction 
= new StringBuilder();
        scriptFunction.Append(
"<script language=‘javascript‘>");
        scriptFunction.Append(
"       function returnTotab()");
        scriptFunction.Append(
"         {");
        scriptFunction.Append(
"          if(event.keyCode==13)    ");
        scriptFunction.Append(
"             {event.keyCode=9;     ");
        scriptFunction.Append(
"               return true;}       ");
        scriptFunction.Append(
"          } ");
        scriptFunction.Append(
"</script>");
        page.ClientScript.RegisterStartupScript(page.GetType(),
"totab", scriptFunction.ToString());

    }

img_2887d91d0594ef8793c1db92b8a1d545.gifimg_7a2b9a960ee9a98bfd25d306d55009f8.gif    
/**//**/
img_2887d91d0594ef8793c1db92b8a1d545.gifimg_7a2b9a960ee9a98bfd25d306d55009f8.gif    
/**//// <summary>
    
/// tab->enter
    
/// </summary>
    
/// <param name="page"></param>

    public static void tabToEnter()
img_2887d91d0594ef8793c1db92b8a1d545.gifimg_7a2b9a960ee9a98bfd25d306d55009f8.gif    
{
        Page page;
        page 
= HttpContext.Current.Handler as System.Web.UI.Page;
        System.Text.StringBuilder scriptFunction 
= new StringBuilder();
        scriptFunction.Append(
"<script language=‘javascript‘>");
        scriptFunction.Append(
"    function Tcheck()");
        scriptFunction.Append(
"         {");
        scriptFunction.Append(
"         if(event.keyCode==8||event.keyCode==9) ");
        scriptFunction.Append(
"          return true;");
        scriptFunction.Append(
"         else ");
        scriptFunction.Append(
"         {");
        scriptFunction.Append(
"          if(((event.keyCode>=48)++(event.keyCode<=57))||((event.keyCode>=96)++(event.keyCode<=105)))");
        scriptFunction.Append(
"              return true;");
        scriptFunction.Append(
"          else");
        scriptFunction.Append(
"          if(event.keyCode==13||event.keyCode==110||event.keyCode==190||event.keyCode==39)");
        scriptFunction.Append(
"             {event.keyCode=9;");
        scriptFunction.Append(
"               return true;}");
        scriptFunction.Append(
"            else");
        scriptFunction.Append(
"              return false;");
        scriptFunction.Append(
"        }");
        scriptFunction.Append(
"          }     ");
        scriptFunction.Append(
"</script>");
        page.ClientScript.RegisterStartupScript(page.GetType(),
"switch", scriptFunction.ToString());
    }

img_2887d91d0594ef8793c1db92b8a1d545.gifimg_7a2b9a960ee9a98bfd25d306d55009f8.gif    
/**//**/
img_2887d91d0594ef8793c1db92b8a1d545.gifimg_7a2b9a960ee9a98bfd25d306d55009f8.gif    
/**//// <summary>
    
/// attachEvent
    
/// </summary>
    
/// <param name="controlToFocus"></param>
    
/// <param name="page"></param>

    public static void attachEvent(Control[] controlToFocus)
img_2887d91d0594ef8793c1db92b8a1d545.gifimg_7a2b9a960ee9a98bfd25d306d55009f8.gif    
{
        Page page;
        page 
= HttpContext.Current.Handler as System.Web.UI.Page;
        System.Text.StringBuilder scriptFunction 
= new StringBuilder();
        
string scriptClientId;
        scriptFunction.Append(
"<script language=‘javascript‘>");

        
foreach (Control con in controlToFocus)
img_2887d91d0594ef8793c1db92b8a1d545.gifimg_7a2b9a960ee9a98bfd25d306d55009f8.gif        
{
            scriptClientId 
= con.ClientID;
            scriptFunction.Append(
"document.getElementById(‘" + scriptClientId + "‘).attachEvent(‘onkeydown‘, Tcheck);");
        }

        scriptFunction.Append(
"</script>");
        page.ClientScript.RegisterStartupScript(page.GetType(),
"attach", scriptFunction.ToString());
    }



img_2887d91d0594ef8793c1db92b8a1d545.gifimg_7a2b9a960ee9a98bfd25d306d55009f8.gif    
/**//**/
img_2887d91d0594ef8793c1db92b8a1d545.gifimg_7a2b9a960ee9a98bfd25d306d55009f8.gif    
/**//// <summary>
    
/// 
    
/// </summary>
    
/// <param name="controlToFocus"></param>
    
/// <param name="page"></param>
    
/// <param name="eventStr"></param>
    
/// <param name="FuncStr"></param>

    public static void AttachEvent(Control[] controlToFocus, string

eventStr, 
string FuncStr)
img_2887d91d0594ef8793c1db92b8a1d545.gifimg_7a2b9a960ee9a98bfd25d306d55009f8.gif    
{
        Page page;
        page 
= HttpContext.Current.Handler as System.Web.UI.Page;
        System.Text.StringBuilder scriptFunction 
= new StringBuilder();
        
string scriptClientId;
        scriptFunction.Append(
"<script language=‘javascript‘>");
        
foreach (Control con in controlToFocus)
img_2887d91d0594ef8793c1db92b8a1d545.gifimg_7a2b9a960ee9a98bfd25d306d55009f8.gif        
{
            scriptClientId 
= con.ClientID;
            scriptFunction.Append(
"document.getElementById(‘" + scriptClientId + "‘).attachEvent(‘" + eventStr + "‘, " + FuncStr + ");");
        }

        scriptFunction.Append(
"</script>");
        page.ClientScript.RegisterStartupScript(page.GetType(),
"attach2", scriptFunction.ToString());
    }

img_2887d91d0594ef8793c1db92b8a1d545.gifimg_7a2b9a960ee9a98bfd25d306d55009f8.gif    
/**//**/
img_2887d91d0594ef8793c1db92b8a1d545.gifimg_7a2b9a960ee9a98bfd25d306d55009f8.gif    
/**//// <summary>
    
/// 
    
/// </summary>
    
/// <param name="page"></param>

        public static void NumOnlyFun()
img_2887d91d0594ef8793c1db92b8a1d545.gifimg_7a2b9a960ee9a98bfd25d306d55009f8.gif        
{
            Page page;
            page 
= HttpContext.Current.Handler as System.Web.UI.Page;
            System.Text.StringBuilder scriptFunction 
= new StringBuilder();
            scriptFunction.Append(
"<script language=‘javascript‘>");
            scriptFunction.Append(
"       function isNum()");
            scriptFunction.Append(
"         {");
            scriptFunction.Append(
"              if(event.keyCode==8||event.keyCode==9) ");
            scriptFunction.Append(
"                  return true;");
            scriptFunction.Append(
"             else ");
            scriptFunction.Append(
"             {");
            scriptFunction.Append(
"          if(((event.keyCode>=48)++(event.keyCode<=57))||((event.keyCode>=96)++(event.keyCode<=105)))");
            scriptFunction.Append(
"              return true;");
            scriptFunction.Append(
"          else");
            scriptFunction.Append(
"                return false;");
            scriptFunction.Append(
"        }");
            scriptFunction.Append(
"          } ");
            scriptFunction.Append(
"</script>");
            page.ClientScript.RegisterStartupScript(page.GetType(), 
"numonly", scriptFunction.ToString());

        }

    
    }


  

}
 
目录
相关文章
|
2月前
|
JavaScript
短小精悍的js代码
【10月更文挑战第17天】
128 58
|
2月前
|
JavaScript 前端开发 开发者
如何在 Visual Studio Code (VSCode) 中使用 ESLint 和 Prettier 来检查代码规范并自动格式化 Vue.js 代码。
【10月更文挑战第7天】随着前端开发技术的快速发展,代码规范和格式化工具变得尤为重要。本文介绍了如何在 Visual Studio Code (VSCode) 中使用 ESLint 和 Prettier 来检查代码规范并自动格式化 Vue.js 代码。通过安装和配置这两个工具,可以确保代码风格一致,提升团队协作效率和代码质量。
264 2
|
2月前
|
JavaScript 前端开发 内存技术
js文件的入口代码及需要入口代码的原因
js文件的入口代码及需要入口代码的原因
44 0
|
14天前
|
JavaScript 前端开发 测试技术
在 golang 中执行 javascript 代码的方案详解
本文介绍了在 Golang 中执行 JavaScript 代码的四种方法:使用 `otto` 和 `goja` 嵌入式 JavaScript 引擎、通过 `os/exec` 调用 Node.js 外部进程以及使用 WebView 嵌入浏览器。每种方法都有其适用场景,如嵌入简单脚本、运行复杂 Node.js 脚本或在桌面应用中显示 Web 内容。
50 15
在 golang 中执行 javascript 代码的方案详解
|
15天前
|
开发框架 .NET PHP
ASP.NET Web Pages - 添加 Razor 代码
ASP.NET Web Pages 使用 Razor 标记添加服务器端代码,支持 C# 和 Visual Basic。Razor 语法简洁易学,类似于 ASP 和 PHP。例如,在网页中加入 `@DateTime.Now` 可以实时显示当前时间。
|
1月前
|
JavaScript
原生js炫酷随机抽奖中奖效果代码
原生js随机抽奖是一个炫酷的根据数据随机抽奖的代码,该网页可进行随机抽取一个数据,页面动画高科技、炫酷感觉的随机抽奖效果,简单好用,欢迎下载!
45 3
原生js炫酷随机抽奖中奖效果代码
|
19天前
|
JSON JavaScript 关系型数据库
node.js连接GBase 8a 数据库 并进行查询代码示例
node.js连接GBase 8a 数据库 并进行查询代码示例
|
1月前
|
JavaScript 前端开发 开发者
如何在 Visual Studio Code (VSCode) 中使用 ESLint 和 Prettier 检查代码规范并自动格式化 Vue.js 代码,包括安装插件、配置 ESLint 和 Prettier 以及 VSCode 设置的具体步骤
随着前端开发技术的快速发展,代码规范和格式化工具变得尤为重要。本文介绍了如何在 Visual Studio Code (VSCode) 中使用 ESLint 和 Prettier 检查代码规范并自动格式化 Vue.js 代码,包括安装插件、配置 ESLint 和 Prettier 以及 VSCode 设置的具体步骤。通过这些工具,可以显著提升编码效率和代码质量。
436 4
|
1月前
|
JSON 移动开发 数据格式
html5+css3+js移动端带歌词音乐播放器代码
音乐播放器特效是一款html5+css3+js制作的手机移动端音乐播放器代码,带歌词显示。包括支持单曲循环,歌词显示,歌曲搜索,音量控制,列表循环等功能。利用json获取音乐歌单和歌词,基于html5 audio属性手机音乐播放器代码。
107 6