开户送体验金无需申请、分享、快乐

开户送体验金无需申请

[08-23]   来源:http://www.tommyzablan.com  NET教程   阅读:290

asp.net里常用的js_asp.net技巧,本站还有更多关于NET教程,asp.net教程,net教程的文章。
正文:

在整理一套OA发现的有些东西,我会陆续拿出给大家。希望对大家有用!:)

代码复制内容到剪贴板
  1. using System;     
  2. using System.Web;     
  3. using System.Web.UI.HtmlControls ;     
  4. using System.Web.UI;     
  5.     
  6. namespace Web.JScript     
  7. {     
  8.     /// <summary>     
  9.     /// 提供向页面输出客户端代码实现特殊功能的方法     
  10.     /// </summary>     
  11.     /// <remarks>     
  12.     /// </remarks>     
  13.     
  14.     public class JScript     
  15.     {     
  16.         public static void AlertAndRedirect(string message,string toURL)     
  17.         {     
  18.             string js = "<script language=javascript>alert({0});window.location.replace({1})</script>";     
  19.             HttpContext.Current.Response.Write(string.Format(js,message ,toURL));     
  20.         }     
  21.     
  22.         /// <summary>     
  23.         /// 向客户端发送函数KendoPostBack(eventTarget, eventArgument)     
  24.         /// 服务器端可接收__EVENTTARGET,__EVENTARGUMENT的值     
  25.         /// </summary>     
  26.         /// <param name="page">System.Web.UI.Page 一般为this</param>     
  27.         public static void JscriptSender(System.Web.UI.Page page)     
  28.         {     
  29.             page.RegisterHiddenField("__EVENTTARGET","");     
  30.             page.RegisterHiddenField("__EVENTARGUMENT","");     
  31.             string s = @"            
  32. <script language=Javascript>    
  33.       function KendoPostBack(eventTarget, eventArgument)     
  34.       {    
  35.                 var theform = document.forms[0];    
  36.                 theform.__EVENTTARGET.value = eventTarget;    
  37.                 theform.__EVENTARGUMENT.value = eventArgument;    
  38.                 theform.submit();    
  39.             }    
  40. </script>";     
  41.                  
  42.             page.RegisterStartupScript("sds",s);     
  43.         }     
  44.         /// <summary>     
  45.         /// 弹出JavaScript小窗口     
  46.         /// </summary>     
  47.         /// <param name="js">窗口信息</param>     
  48.         public static void Alert(string message)     
  49.         {     
  50.             message = StringUtil.DeleteUnVisibleChar(message);     
  51.             string [email protected]"<Script language=JavaScript>    
  52.                     alert("+ message +");</Script>";     
  53.             HttpContext.Current.Response.Write(js);     
  54.         }     
  55.         public static void Alert(object message)     
  56.         {     
  57.             string [email protected]"<Script language=JavaScript>    
  58.                     alert({0});      
  59.                   </Script>";     
  60.             HttpContext.Current.Response.Write(string.Format(js,message.ToString()));     
  61.         }     
  62.     
  63.         public static void RtnRltMsgbox(object message,string strWinCtrl)     
  64.         {        
  65.             string js = @"<Script language=JavaScript>    
  66.                      strWinCtrl = true;    
  67.                      strWinCtrl = if(!confirm("+ message +"))return false;</Script>";     
  68.             HttpContext.Current.Response.Write(string.Format(js,message.ToString()));     
  69.         }     
  70.              
  71.         /// <summary>     
  72.         /// 回到历史页面     
  73.         /// </summary>     
  74.         /// <param name="value">-1/1</param>     
  75.         public static void GoHistory(int value)     
  76.         {     
  77.             string [email protected]"<Script language=JavaScript>    
  78.                     history.go({0});      
  79.                   </Script>";     
  80.             HttpContext.Current.Response.Write(string.Format(js,value));     
  81.         }     
  82.     
  83.         /// <summary>     
  84.         /// 关闭当前窗口     
  85.         /// </summary>     
  86.         public static void CloseWindow()     
  87.         {     
  88.             string [email protected]"<Script language=JavaScript>    
  89.                     window.close();      
  90.                   </Script>";     
  91.             HttpContext.Current.Response.Write(js);          
  92.             HttpContext.Current.Response.End();       
  93.         }     
  94.     
  95.         /// <summary>     
  96.         /// 刷新父窗口     
  97.         /// </summary>     
  98.         public static void RefreshParent()     
  99.         {     
  100.             string [email protected]"<Script language=JavaScript>    
  101.                     parent.location.reload();    
  102.                   </Script>";     
  103.             HttpContext.Current.Response.Write(js);          
  104.         }     
  105.     
  106.         /// <summary>     
  107.         /// 格式化为JS可解释的字符串     
  108.         /// </summary>     
  109.         /// <param name="s"></param>     
  110.         /// <returns></returns>     
  111.         public static string JSStringFormat(string s)     
  112.         {     
  113.             return s.Replace("\r","\\r").Replace("\n","\\n").Replace("","\\").Replace("\"","\\\"");     
  114.         }     
  115.     
  116.         /// <summary>     
  117.         /// 刷新打开窗口     
  118.         /// </summary>     
  119.         public static void RefreshOpener()     
  120.         {     
  121.             string [email protected]"<Script language=JavaScript>    
  122.                     opener.location.reload();    
  123.                   </Script>";     
  124.             HttpContext.Current.Response.Write(js);          
  125.         }     
  126.     
  127.         /// <summary>     
  128.         /// 打开窗口     
  129.         /// </summary>     
  130.         /// <param name="url"></param>     
  131.         public static void OpenWebForm(string url)     
  132.         {     
  133.             /*…………………………………………………………………………………………*/     
  134.             /*修改目的:    新开页面去掉ie的菜单。。。                        */     
  135.     
  136.             string [email protected]"<Script language=JavaScript>    
  137.             //window.open("[email protected]");    
  138.             window.open("[email protected]",,height=0,width=0,top=0,left=0,location=no,menubar=no,resizable=yes,scrollbars=yes,status=yes,titlebar=no,toolbar=no,directories=no);    
  139.             </Script>";     
  140.             /*结束*/     
  141.             /*…………………………………………………………………………………………*/     
  142.                           
  143.                      
  144.             HttpContext.Current.Response.Write(js);          
  145.         }     
  146.         public static void OpenWebForm(string url,string name,string future)     
  147.         {     
  148.             string [email protected]"<Script language=JavaScript>    
  149.                      window.open("[email protected]","[email protected]","[email protected]")    
  150.                   </Script>";     
  151.             HttpContext.Current.Response.Write(js);          
  152.         }     
  153.         public static void OpenWebForm(string url,string formName)     
  154.         {     
  155.             /*…………………………………………………………………………………………*/     
  156.             /*修改目的:    新开页面去掉ie的菜单。。。                        */     
  157.             /*注释内容:                                */     
  158.             /*开始*/     
  159.             string [email protected]"<Script language=JavaScript>    
  160.             window.open("[email protected]","[email protected]",height=0,width=0,top=0,left=0,location=no,menubar=no,resizable=yes,scrollbars=yes,status=yes,titlebar=no,toolbar=no,directories=no);    
  161.             </Script>";     
  162.             /*结束*/     
  163.             /*…………………………………………………………………………………………*/     
  164.     
  165.             HttpContext.Current.Response.Write(js);          
  166.         }     
  167.     
  168.         /// <summary>             
  169.         /// 函数名:OpenWebForm         
  170.         /// 功能描述:打开WEB窗口         
  171.         /// </summary>     
  172.         /// <param name="url">WEB窗口</param>     
  173.         /// <param name="isFullScreen">是否全屏幕</param>     
  174.         public static void OpenWebForm(string url,bool isFullScreen)     
  175.         {                 
  176.             string [email protected]"<Script language=JavaScript>";     
  177.             if(isFullScreen)     
  178.             {     
  179.                 js+="var iWidth = 0;";     
  180.                 js+="var iHeight = 0;";     
  181.                 js+="iWidth=window.screen.availWidth-10;";     
  182.                 js+="iHeight=window.screen.availHeight-50;";     
  183.                 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;";     
  184.                 js+="window.open("[email protected]",,szFeatures);";     
  185.             }     
  186.             else     
  187.             {     
  188.                 js+="window.open("[email protected]",,height=0,width=0,top=0,left=0,location=no,menubar=no,resizable=yes,scrollbars=yes,status=yes,titlebar=no,toolbar=no,directories=no);";     
  189.             }     
  190.             js+="</Script>";     
  191.             HttpContext.Current.Response.Write(js);          
  192.         }     
  193.     
  194.         /// <summary>     
  195.         /// 转向Url制定的页面     
  196.         /// </summary>     
  197.         /// <param name="url"></param>     
  198.         public static void JavaScriptLocationHref(string url)     
  199.         {     
  200.             string [email protected]"<Script language=JavaScript>    
  201.                     window.location.replace({0});    
  202.                   </Script>";     
  203.             js=string.Format(js,url);     
  204.             HttpContext.Current.Response.Write(js);       
  205.         }     
  206.     
  207.         /// <summary>     
  208.         /// 指定的框架页面转换     
  209.         /// </summary>     
  210.         /// <param name="FrameName"></param>     
  211.         /// <param name="url"></param>     
  212.         public static void JavaScriptFrameHref(string FrameName,string url)     
  213.         {     
  214.             string [email protected]"<Script language=JavaScript>    
  215.                         
  216.                     @obj.location.replace(""{0}"");    
  217.                   </Script>";     
  218.             js = js.Replace("@obj",FrameName );     
  219.             js=string.Format(js,url);     
  220.             HttpContext.Current.Response.Write(js);       
  221.         }     
  222.     
  223.         /// <summary>     
  224.         ///重置页面     
  225.         /// </summary>     
  226.         public static void JavaScriptResetPage(string strRows)     
  227.         {     
  228.             string [email protected]"<Script language=JavaScript>    
  229.                     window.parent.CenterFrame.rows="+strRows+";</Script>";     
  230.             HttpContext.Current.Response.Write(js);      
  231.         }     
  232.     
  233.         /// <summary>     
  234.         /// 函数名:JavaScriptSetCookie     
  235.         /// 功能描述:客户端方法设置Cookie     
  236.         /// </summary>     
  237.         /// <param name="strName">Cookie名</param>     
  238.         /// <param name="strValue">Cookie值</param>     
  239.         public static void JavaScriptSetCookie(string strName,string strValue)     
  240.         {     
  241.             string [email protected]"<script language=Javascript>    
  242.             var the_cookie = "+strName+"="[email protected]"    
  243.             var dateexpire = Tuesday, 01-Dec-2020 12:00:00 GMT;    
  244.             //document.cookie = the_cookie;//写入Cookie<BR>} <BR>    
  245.             document.cookie = the_cookie + ; expires=+dateexpire;                
  246.             </script>";     
  247.             HttpContext.Current.Response.Write(js);      
  248.         }     
  249.     
  250.         /// <summary>             
  251.         /// 函数名:GotoParentWindow         
  252.         /// 功能描述:返回父窗口         
  253.         /// </summary>     
  254.         /// <param name="parentWindowUrl">父窗口</param>             
  255.         public static void GotoParentWindow(string parentWindowUrl)     
  256.         {                 
  257.             string [email protected]"<Script language=JavaScript>    
  258.                     this.parent.location.replace("+parentWindowUrl+");</Script>";     
  259.             HttpContext.Current.Response.Write(js);                  
  260.         }     
  261.     
  262.         /// <summary>             
  263.         /// 函数名:ReplaceParentWindow         
  264.         /// 功能描述:替换父窗口         
  265.         /// </summary>     
  266.         /// <param name="parentWindowUrl">父窗口</param>     
  267.         /// <param name="caption">窗口提示</param>     
  268.         /// <param name="future">窗口特征参数</param>     
  269.         public static void ReplaceParentWindow(string parentWindowUrl,string caption,string future)     
  270.         {         
  271.             string js="";     
  272.             if(future!=null&&future.Trim()!="")     
  273.             {     
  274.                 [email protected]"<script language=javascript>this.parent.location.replace("+parentWindowUrl+","+caption+","+future+");</script>";     
  275.             }     
  276.             else     
  277.             {     
  278.                 [email protected]"<script language=javascript>var iWidth = 0 ;var iHeight = 0 ;iWidth=window.screen.availWidth-10;iHeight=window.screen.availHeight-50;    
  279.                             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>";     
  280.             }     
  281.     
  282.             HttpContext.Current.Response.Write(js);     
  283.         }     
  284.                      
  285.         /// <summary>             
  286.         /// 函数名:ReplaceOpenerWindow         
  287.         /// 功能描述:替换当前窗体的打开窗口         
  288.         /// </summary>     
  289.         /// <param name="openerWindowUrl">当前窗体的打开窗口</param>             
  290.         public static void ReplaceOpenerWindow(string openerWindowUrl)     
  291.         {                 
  292.             string [email protected]"<Script language=JavaScript>    
  293.                     window.opener.location.replace("+openerWindowUrl+");</Script>";     
  294.             HttpContext.Current.Response.Write(js);                  
  295.         }     
  296.     
  297.         /// <summary>             
  298.         /// 函数名:ReplaceOpenerParentWindow         
  299.         /// 功能描述:替换当前窗体的打开窗口的父窗口         
  300.         /// </summary>     
  301.         /// <param name="openerWindowUrl">当前窗体的打开窗口的父窗口</param>             
  302.         public static void ReplaceOpenerParentFrame(string frameName,string frameWindowUrl)     
  303.         {                 
  304.             string [email protected]"<Script language=JavaScript>    
  305.                     window.opener.parent." + frameName + ".location.replace("+frameWindowUrl+");</Script>";     
  306.             HttpContext.Current.Response.Write(js);                  
  307.         }     
  308.     
  309.         /// <summary>             
  310.         /// 函数名:ReplaceOpenerParentWindow         
  311.         /// 功能描述:替换当前窗体的打开窗口的父窗口         
  312.         /// </summary>     
  313.         /// <param name="openerWindowUrl">当前窗体的打开窗口的父窗口</param>             
  314.         public static void ReplaceOpenerParentWindow(string openerParentWindowUrl)     
  315.         {                 
  316.             string [email protected]"<Script language=JavaScript>    
  317.                     window.opener.parent.location.replace("+openerParentWindowUrl+");</Script>";     
  318.             HttpContext.Current.Response.Write(js);                  
  319.         }     
  320.     
  321.         /// <summary>             
  322.         /// 函数名:CloseParentWindow         
  323.         /// 功能描述:关闭窗口         
  324.         /// </summary>     
  325.         public static void CloseParentWindow()     
  326.         {                 
  327.             string [email protected]"<Script language=JavaScript>    
  328.                     window.parent.close();      
  329.                   </Script>";     
  330.             HttpContext.Current.Response.Write(js);     
  331.         }     
  332.              
  333.         public static void CloseOpenerWindow()     
  334.         {                 
  335.             string [email protected]"<Script language=JavaScript>    
  336.                     window.opener.close();      
  337.                   </Script>";     
  338.             HttpContext.Current.Response.Write(js);     
  339.         }             
  340.     
  341.         /// <summary>     
  342.         /// 函数名:ShowModalDialogJavascript         
  343.         /// 功能描述:返回打开模式窗口的脚本         
  344.         /// </summary>     
  345.         /// <param name="webFormUrl"></param>     
  346.         /// <returns></returns>     
  347.         public static string ShowModalDialogJavascript(string webFormUrl)     
  348.         {     
  349.             string [email protected]"<script language=javascript>    
  350.                             var iWidth = 0 ;    
  351.                             var iHeight = 0 ;    
  352.                             iWidth=window.screen.availWidth-10;    
  353.                             iHeight=window.screen.availHeight-50;    
  354.                             var szFeatures = dialogWidth:+iWidth+;dialogHeight:+iHeight+;dialogLeft:0px;dialogTop:0px;center:yes;help=no;resizable:on;status:on;scroll=yes;    
  355.                             showModalDialog("+webFormUrl+",,szFeatures);</script>";     
  356.             return js;     
  357.         }     
  358.     
  359.         public static string ShowModalDialogJavascript(string webFormUrl,string features)     
  360.         {     
  361.             string [email protected]"<script language=javascript>                                
  362.                             showModalDialog("+webFormUrl+",,"+features+");</script>";     
  363.             return js;     
  364.         }     
  365.     
  366.         /// <summary>     
  367.         /// 函数名:ShowModalDialogWindow         
  368.         /// 功能描述:打开模式窗口         
  369.         /// </summary>     
  370.         /// <param name="webFormUrl"></param>     
  371.         /// <returns></returns>     
  372.         public static void ShowModalDialogWindow(string webFormUrl)     
  373.         {     
  374.             string js=ShowModalDialogJavascript(webFormUrl);     
  375.             HttpContext.Current.Response.Write(js);     
  376.         }     
  377.     
  378.         public static void ShowModalDialogWindow(string webFormUrl,string features)     
  379.         {     
  380.             string js=ShowModalDialogJavascript(webFormUrl,features);     
  381.             HttpContext.Current.Response.Write(js);     
  382.         }     
  383.         public static void ShowModalDialogWindow(string webFormUrl,int width,int height,int top,int left)     
  384.         {     
  385.             string features = "dialogWidth:"+width.ToString() + "px"    
  386.                 +";dialogHeight:" + height.ToString() + "px"      
  387.                 +";dialogLeft:" + left.ToString() + "px"    
  388.                 +";dialogTop:" + top.ToString() + "px"    
  389.                 +";center:yes;help=no;resizable:no;status:no;scroll=no";     
  390.             ShowModalDialogWindow(webFormUrl,features);                 
  391.         }     
  392.     
  393.         public static void SetHtmlElementValue(string formName,string elementName,string elementValue)     
  394.         {                 
  395.             string [email protected]"<Script language=JavaScript>if(document."+formName+"." + elementName +"!=null){document."+formName+"." + elementName +".value ="+ elementValue +";}</Script>";     
  396.             HttpContext.Current.Response.Write(js);     
  397.         }             
  398.     }     
  399. }     
  400.     



如果觉得asp.net里常用的js_asp.net技巧不错,可以推荐给好友哦。
Tag:NET教程asp.net教程,net教程电脑开户送体验金无需申请 - 编程入门 - NET教程