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

推荐订阅源

V2EX - 技术
V2EX - 技术
酷 壳 – CoolShell
酷 壳 – CoolShell
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
阮一峰的网络日志
阮一峰的网络日志
GbyAI
GbyAI
The Cloudflare Blog
小众软件
小众软件
MyScale Blog
MyScale Blog
IT之家
IT之家
H
Help Net Security
宝玉的分享
宝玉的分享
V
Visual Studio Blog
Hugging Face - Blog
Hugging Face - Blog
F
Fortinet All Blogs
博客园_首页
S
SegmentFault 最新的问题
MongoDB | Blog
MongoDB | Blog
The Hacker News
The Hacker News
有赞技术团队
有赞技术团队
Microsoft Security Blog
Microsoft Security Blog
Know Your Adversary
Know Your Adversary
Project Zero
Project Zero
P
Palo Alto Networks Blog
博客园 - 聂微东
罗磊的独立博客
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Engineering at Meta
Engineering at Meta
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
U
Unit 42
Spread Privacy
Spread Privacy
NISL@THU
NISL@THU
Cisco Talos Blog
Cisco Talos Blog
Last Week in AI
Last Week in AI
L
Lohrmann on Cybersecurity
J
Java Code Geeks
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Cyberwarzone
Cyberwarzone
G
Google Developers Blog
C
Cybersecurity and Infrastructure Security Agency CISA
大猫的无限游戏
大猫的无限游戏
Microsoft Azure Blog
Microsoft Azure Blog
L
LangChain Blog
The GitHub Blog
The GitHub Blog
Jina AI
Jina AI
Blog — PlanetScale
Blog — PlanetScale
C
Cyber Attacks, Cyber Crime and Cyber Security
L
LINUX DO - 热门话题
T
Tailwind CSS Blog
雷峰网
雷峰网
C
Cisco Blogs

博客园 - ceocio

Hire system develop leader 招一名熟悉Excel的同学 继续招聘 新年快乐&再次寻人 事隔半年重开“以球会友” Newegg Chengdu Now Hiring!!! 约球 重庆专场招聘会 招聘BI方面人才 重庆招聘 training 招聘:OLAP Programmer 技术8年 Newegg Chengdu MIS 文档工程师 招聘 技术支持工程师(成都) 本周继续以球会友!!! 以球会友。 [导入]春节快乐~ [导入]开心的讲座
[导入]asp.net多按钮回发
ceocio · 2005-01-06 · via 博客园 - ceocio

问题描述:

有两个button,两个textbox,需要输入textbox1后回车就postback到button1的后端事件,textbox2类似。很明显需要在客户端代码实现。

解决方法:

首先了解.Net中控制控件的postback是通过这个js函数控制的:

<script language="javascript" type="text/javascript">
 <!--
 function __doPostBack(eventTarget, eventArgument) {
 var theform;
 if (window.navigator.appName.toLowerCase().indexOf("microsoft") > -1) {
 theform = document.Form1;
 }
 else {
 theform = document.forms["Form1"];
 }
 theform.__EVENTTARGET.value = eventTarget.split("$").join(":");
 theform.__EVENTARGUMENT.value = eventArgument;
 theform.submit();
 }
 // -->
 </script>

也必须添加两个hidden的文本框到客户端,写到<form>中

<input type="hidden" name="__EVENTTARGET">

<input type="hidden" name="__EVENTARGUMENT">

后端.cs文件中的Page_Load添加:

TextBox1.Attributes.Add("onkeydown","javascript:if (13 == window.event.keyCode){__doPostBack('Button1','');return false;}");
   TextBox2.Attributes.Add("onkeydown","javascript:if (13 == window.event.keyCode){__doPostBack('Button2','');return false;}");

实现。这实际上是将微软本身提供的体制反着用了一次,不得已而为之,但总算实现了。


文章来源:http://blog.joycode.com/ceocio/archive/2005/01/05/42429.aspx