惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

P
Privacy & Cybersecurity Law Blog
V
V2EX
月光博客
月光博客
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
The Register - Security
The Register - Security
MongoDB | Blog
MongoDB | Blog
P
Privacy International News Feed
The Last Watchdog
The Last Watchdog
Security Archives - TechRepublic
Security Archives - TechRepublic
美团技术团队
Stack Overflow Blog
Stack Overflow Blog
博客园 - 司徒正美
博客园 - 三生石上(FineUI控件)
V
Visual Studio Blog
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
K
Kaspersky official blog
S
Secure Thoughts
T
Tenable Blog
Security Latest
Security Latest
The Cloudflare Blog
S
Security @ Cisco Blogs
H
Heimdal Security Blog
aimingoo的专栏
aimingoo的专栏
TaoSecurity Blog
TaoSecurity Blog
Blog — PlanetScale
Blog — PlanetScale
Microsoft Security Blog
Microsoft Security Blog
Schneier on Security
Schneier on Security
Webroot Blog
Webroot Blog
G
Google Developers Blog
www.infosecurity-magazine.com
www.infosecurity-magazine.com
Scott Helme
Scott Helme
IT之家
IT之家
Latest news
Latest news
The Hacker News
The Hacker News
C
Check Point Blog
T
The Exploit Database - CXSecurity.com
H
Hackread – Cybersecurity News, Data Breaches, AI and More
腾讯CDC
C
CERT Recently Published Vulnerability Notes
NISL@THU
NISL@THU
N
News | PayPal Newsroom
Forbes - Security
Forbes - Security
P
Palo Alto Networks Blog
S
Security Affairs
S
Securelist
Google Online Security Blog
Google Online Security Blog
WordPress大学
WordPress大学
Last Week in AI
Last Week in AI
C
Cybersecurity and Infrastructure Security Agency CISA
A
About on SuperTechFans

博客园 - 稽首本然

Nhibernate 教程,有空看看 Jquery专题写的不少,有空看看,另该研究下门面模式了! Java开源权限管理中间件 《需求规格说明书》业务描述活动图 《需求规格说明书》(用例)陷阱 《需求规格说明书》核心功能表现方式(用例) LINQ TO SQL ScriptManager与UpdatePanel总结 Nunti测试工具使用整理 一个关于NHiberante,Linq数据源与UI交互引发的思考 数据库联接字符串 LINQ TO OBJECT ASPX直接编写脚本function后使用javascript Aspx页面中直接编写javascript脚本 母版事件中注册javascript脚本 ASPNET跨页面传值技巧总结 javascript捣乱程序 AjaxPanel中使用javascript AjaxPanel控件说明
Javascript在Asp.Net中的应用汇总
稽首本然 · 2011-01-18 · via 博客园 - 稽首本然

Javascript Asp.Net 中的应用汇总

aspx文件中的用 javscript 脚本为件添加事

javascript 开新窗

javascript 打开新窗体

protected void NextPageParameters (

string strPageTo,string [] strKeys,object [] obValues,boo l bNewWindow,int nWidth,int nHeight )

{

      if( strPageTo == null || strPageTo.Length == 0)

      throw new ArgumentNullException ("PageBase "," 必须提供将要跳转到的页面的名称! ") ;

      if( (strKeys == null && obValues != null) || (obValues == null && strKeys != null)

||( strKeys != null && obValues != null && strKeys.Length !=obValues.Length ))

      throw new ArgumentNullException ("PageBase "," 参数名和参数值个数不一致或者为空! ") ;

      string[ ] strPageToArray = strPageTo.Split ('?') ;

      string url = strPageToArray [0] ;

      // 得到原先存在的参数

      string strOldParas = strPageToArray.Length > 1 ? strPageToArray [ 1] : string.Empty ;

      short shtParamCount = 0 ;

      //bool bAsk = false ;

      System.Text.StringBuilder strBuilder = new System.Text.StringBuilder ( url ) ;

      if( strKeys != null && obValues != null && obValues.Length > 0 )

      {

           strBuilder.Append ( '?' ) ;

      //   bAsk = true ;

           for( int i = 0 ; i < strKeys.Length ; i ++ )

           {

                 if( strKeys [i ] != null)

                 {

                      if( shtParamCount ++ > 0 )

                      strBuilder.Append ( "&" ) ;//&//&amp;

                      strBuilder.Append ( strKeys [i ] ) ;

                      strBuilder.Append ( '=' ) ;

                      strBuilder.Append ( obValues [i ] == null ? "" : obValues [i ].ToString () ) ;

                 }

           }

                      //shtParamCount = 0 ;

}

      if( strOldParas != null && !strOldParas.Equals (String.Empty ) )

      {

           //if( !bAsk )

           if( shtParamCount == 0 )strBuilder.Append ( '?' ) ;

           string[ ,] strParametrs = Util.Str.GetCodeNameArray (strOldParas ,'&','=') ;

           for( int i = 0 ; i < strParametrs.Length/2 ; i ++)

                 {

                      if( shtParamCount ++ > 0 )strBuilder.Append ( "&" ) ;//&//&amp;

strBuilder.Append ( strParametrs [i,0] ) ;

                      strBuilder.Append ( '=' ) ;

                      strBuilder.Append ( strParametrs [i,1] == null ? "" : strParametrs [i,1] ) ;

                 }

      }

      url = strBuilder.ToString () ;

      //navgation

      if( bNewWindow )

      {

           this.Response.Write ( "<script language=JavaScript> "

           +"function ShowDialog ( url,iWidth,iHeight ) { "

           +"var iTop =( window.screen.height-iHeight )/2;var iLeft =(window.screen.width-iWidth )/2;    "

           +"var DialogPath ='scrollbars=yes,toolbar =no,resizable =yes,

status = no,menubar = no,titlebar =no,location =yes,Width ='+iWidth +' ,Height='+iHeight

+',Top ='+iTop+',Left ='+iLeft;"+"window.open (url,'',DialogPath ); } ");

           string strB = " ShowDialog (' "+(url == "" ? strPageTo : url )+"',"+nWidth+","+nHeight +");</script> ";

           Response.Write ( strB ) ;

      }

      else

           Response.Redirect ( url == "" ? strPageTo : url ) ;

}

<返回 >

. aspx 文件中的用 javscript 脚本为控件添加事件

<head >

<script language="javascript ">

function displayDiv1 ()

{

      document .getElementById ( "Div1").style .display ="";

}

</script>

</head>

<body >

<form id="Form1" method="post" runat ="server">

<input type ="button" id="btn2" runat ="server" value ="displayDiv " onclick ="displayDiv1( ) ">

<br >

<div id="Div1" style ="DISPLAY: none; BACKGROUND -COLOR: #009999" runat ="server">

一个 DIV 图层

</div>

<br >

</form>

</body>

aspx.cs 文件中实现上面同样的效果,后台执行 javascript 脚本

A :测试一个带 alert() 的脚本文件,在 .cs 中执行

//Page_Load () 中添加:

JavascriptRegistEnvent () // 在页面显示之前向页面中写入脚本

// 定义 javascriptRegistEvent ()

public Void JavascriptRegistEvent (object sender,EventArgs e)

{

Response.Write ( "run CustomEvent ()...");

Response.Write ( "Regisit dispalyJavascript ....");

// 测试可用

StringBuilder builder=new StringBuilder ( );

builder.Append ( "<script langugage ='javascript '> ");

builder.Append ( "function displayDiv () ");

builder.Append ( "{ ");

builder.Append ( "alert('abc '); ");

builder.Append ( "document .getElementById ('Div1').style.display =''; ");

builder.Append ( "} ");

builder.Append ( "</script> ");

Response.Write ( builder.ToString ());

if( !IsStartupScriptRegistered ("Startup"))

{

this.RegisterStartupScript ( "Startup",builder.ToString ());

this.bnt1.Attributes.Add( "Onclick ", "displayDiv ()");

}

}

// 效果如前台脚本一致吗?似乎有问题!

<返回 >