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

推荐订阅源

爱范儿
爱范儿
博客园_首页
W
WeLiveSecurity
S
Secure Thoughts
S
Security @ Cisco Blogs
Recent Commits to openclaw:main
Recent Commits to openclaw:main
Hugging Face - Blog
Hugging Face - Blog
www.infosecurity-magazine.com
www.infosecurity-magazine.com
H
Hacker News: Front Page
Project Zero
Project Zero
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
U
Unit 42
N
News and Events Feed by Topic
N
News and Events Feed by Topic
Hacker News - Newest:
Hacker News - Newest: "LLM"
Forbes - Security
Forbes - Security
T
Tor Project blog
I
Intezer
B
Blog
F
Full Disclosure
Security Archives - TechRepublic
Security Archives - TechRepublic
F
Fortinet All Blogs
Schneier on Security
Schneier on Security
T
Threat Research - Cisco Blogs
AI
AI
Google DeepMind News
Google DeepMind News
L
LINUX DO - 最新话题
Cloudbric
Cloudbric
L
Lohrmann on Cybersecurity
WordPress大学
WordPress大学
博客园 - 聂微东
雷峰网
雷峰网
P
Privacy International News Feed
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
PCI Perspectives
PCI Perspectives
Y
Y Combinator Blog
Spread Privacy
Spread Privacy
Simon Willison's Weblog
Simon Willison's Weblog
罗磊的独立博客
Vercel News
Vercel News
A
Arctic Wolf
The Register - Security
The Register - Security
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Microsoft Azure Blog
Microsoft Azure Blog
H
Heimdal Security Blog
Know Your Adversary
Know Your Adversary
P
Proofpoint News Feed
C
Cybersecurity and Infrastructure Security Agency CISA
P
Proofpoint News Feed

博客园 - Niyo Wong

用于主题检测的临时日志(f89708b9-f679-4391-af74-c92d9138aed4 - 3bfe001a-32de-4114-a6b4-4005b770f6d7) 测试用Word 2007发布博客 【转】ASP.NET Page事件的执行顺序 ASP.NET页面请求过程 JSP 执行过程 SQL Server 2005 错误处理笔记 .Net内存分配笔记 UML入门 与健康有约——送给每一个关心自己身体的人 .net 如何设置和检索特性信息(attribute) VC++(MFC)数据库程序——入门 T-SQL编程基础-游标 .net中的4种事务总结 T-SQL编程基础-基本语法 模式窗口页面不更新的问题 ASP.NET菜鸟进阶-Response.Write与RegisterXXX ASP.NET菜鸟进阶-页面间参数传递 差点把这好地儿给荒废了 我们的生活离不开笑
Javascript调用服务器端事件
Niyo Wong · 2007-08-16 · via 博客园 - Niyo Wong

原本这是个很简单的问题,但不知道的话,却很难想到。
1.在Javascript中调用后台函数
在这个例子中该方法并不是好的解决方案,在这里只是作为示例。
a. 添加一个submit按钮,如代码第18行,其onserverclick事件等于服务器端事件SetValue
b.在后台代码中添加SetValue方法,注意其是一个protected方法,不能为private。
c.在应用中,通过调用submit按钮的click()事件在调用SetValue方法。在示例中是在button的onclick事件中调用。
客户端代码:

 1<%@ Page language="c#" Codebehind="WebForm1.aspx.cs" AutoEventWireup="false" Inherits="WebTest.WebForm1" %>
 2<HTML>
 3    <HEAD>
 4        <title>WebForm1</title>
 5        <script language="javascript">            
 6        function ClientSetValue()
 7        {
 8            document.Form1.smtSetValue.click();
 9        }

10        
</script>
11    </HEAD>
12    <body>
13        <form id="Form1" method="post" runat="server">            
14            <dir>
15                <input type="text" id="txtSetValue" runat="server" /> 
16                <input type="button" id="btnSetValue" onclick="ClientSetValue();" value="Set value" />
17            </dir>
18            <input type="submit" onserverclick="SetValue" id="smtSetValue" runat="server" style="DISPLAY:none" value="Submit Query">
19        </form>
20    </body>
21</HTML>
22

服务器端代码:

1protected void SetValue(object sender, System.EventArgs e)
2        {
3            this.txtSetValue.Value = "The value from server!";
4        }

2.在控件中调用后台函数
该方法在上例中其实已经提到,也是我们很常用的一种方法。
a.在控件的onserverclick,或者onserverchange事件中直接调用服务器端事件,忘了提醒,该事件不要在服务器端声明委托。如上例中的18行就是用的该方法。

3.常规用法。
常规用法就是在服务器端声明委托。如:

1/// <summary>
2        /// 设计器支持所需的方法 - 不要使用代码编辑器修改
3        /// 此方法的内容。
4        /// </summary>
5        private void InitializeComponent()
6        {    
7            this.smtSetValue.ServerClick += new System.EventHandler(this.smtSetValue_ServerClick);
8
9        }

完!