ClientScriptManager用法

简介:

aspx 文件代码

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="ClientScriptManager.aspx.cs"Inherits="Demo4_ClientScriptManager" %>

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

 

<html xmlns="http://www.w3.org/1999/xhtml" >

<head runat="server">

    <title>ClientScriptManager</title>

</head>

<body>

    <form id="form1" runat="server">

         <asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />

    </form>

</body>

</html>


.aspx.cs文件代码

using System;

using System.Data;

using System.Configuration;

using System.Collections;

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;

 

public partial class Demo4_ClientScriptManager : System.Web.UI.Page

{

    protected void Page_Load(object sender, EventArgs e)

    {

    }

     protected void Button1_Click(object sender, EventArgs e)

     {

         ClientScriptManager cs = this.ClientScript;

         cs.RegisterArrayDeclaration("Hello""1, 2, 3");//#1

         cs.RegisterClientScriptBlock(this.GetType(), "HelloWorld""function helloWorld(){alert(1);}"true);//#2

         cs.RegisterClientScriptInclude("HelloWorld""HelloWorld.js");//#3

         cs.RegisterExpandoAttribute(this.Button1.ClientID, "Hello""World");//#4

         cs.RegisterHiddenField("hello""world");//#5

         cs.RegisterOnSubmitStatement(this.GetType(), "HelloWorld""return window.confirm('Do you really want to submit the form?')");//#6

         cs.RegisterStartupScript(this.GetType(), "HelloWorld""<script>alert('The page has loaded!')</script>");//#7

     }

}

生成页面的HTML代码

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"

"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >

 

<head><title>ClientScriptManager</title></head>

 

<body>

<form    

"id="form1"

name="form1" 

method="post"

action="ClientScriptManager.aspx"

onsubmit="javascript:return

WebForm_OnSubmit();>

 

<div>

<!--   #5   -->

<input type="hidden" name="hello" id="hello" value="world" />

<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwUKMTQ2OTkzNDMyMWRkdcWxeVaF9qGYsIaDUa9Rcaihgnk=" />

</div>

 

<!--   #2   -->

<script type="text/javascript">

<!--

function helloWorld(){alert(1);}// -->

</script>

 

<!--   #3   -->

<script src="HelloWorld.js" type="text/javascript"></script>

 

<!--   #6   -->

<script type="text/javascript">

<!--

function WebForm_OnSubmit() {

return window.confirm('Do you really want to submit the form?');

return true;

}

// -->

</script>

 

<input type="submit" name="Button1" value="Button" id="Button1" />

 

<!--   #1   -->

<script type="text/javascript">

<!--

var Hello =  new Array(1, 2, 3);

// -->

</script>

 

<!--   #4   -->

<script type="text/javascript">

<!--

var Button1 = document.all ? document.all["Button1"] : document.getElementById("Button1");

Button1.Hello = "World";

// -->

</script>

 

<div>

       <input

type="hidden"

      name="__EVENTVALIDATION" id="__EVENTVALIDATION"

value="/wEWAgKet4KWBgKM54rGBikWLuZSHp4emnxNA3F0qTbFNfuo" />

</div>

<!--   #7   -->

<script>alert('The page has loaded!')</script>

</form>

</body>

</html>




本文转自94cool博客园博客,原文链接:http://www.cnblogs.com/94cool/archive/2010/10/12/1848828.html,如需转载请自行联系原作者

目录
打赏
0
0
0
0
46
分享
相关文章
NSJSONSerialization的简单用法
NSJSONSerialization 苹果官方给出的解析方式是性能最优越的,虽然用起来稍显复杂。 首先我们在上面已经有了我希望得到的信息的网站的API给我们的URL,在OC中,我要加载一个NSURL对象,来向网站提交一个Request。
1134 0
CComPtr用法
<p>COM接口指针很危险,因为使用过程中需要每一个使用者都要严格并且正确的AddRef和Release,一旦出现问题,就会造成对象不能被正常释放,或者对象被重复删除,造成程序崩溃。所以使用COM接口,必须小心翼翼才行。<br> 但是,即使所有的代码中,都正确的AddRef和Release,也不一定能保证万无一失,例如:<br> void SomeApp( IHello * pHell
1882 0
__name__的基本用法
__name__的基本用法
115 0
TkMybatis用法总结
TkMybatis用法总结
219 0
DatabaseMetaData的用法(转)
DatabaseMetaData的用法(转)
613 0
RACSignal的八种常用用法
RACSignal的八种常用用法
96 0

热门文章

最新文章