回发模拟按钮单击 [英] postback simulating button click

查看:71
本文介绍了回发模拟按钮单击的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有消息输入屏幕,这引起了我一些问题。在

时刻,有2个按钮,一个用于向另一个用户发送消息

(btnSend),另一个用于向所有用户发送消息(btnSendAll) 。


当用户点击进入时,我也会模拟点击按钮

(btnSend)的效果。但是,我发现btnSend并不会触发(除非我点击

按钮)。


我调用的回发函数如下:

函数__doPostBack(eventTarget,eventArgument)

{

var theform;

if(window.navigator.appName。 toLowerCase()。indexOf(" n etscape")> -1)

{

theform = document.forms [" Form1"];

}

其他

{

theform = document.Form1;

}

theform.submit();

}


用于引发回发的脚本如下:

< script language =" javascript">

var mykey;

var posted = false;


if(window .Event){

document.captureEvents(Event.KEYDOWN);

}


document.onkeydown = myKeyDown;


函数myKeyDown(e){


if(window.Event){

mykey = e.which;

}

else {

mykey = event.keyCode;

}

// alert(mykey);

if((mykey == 13)&& (发布==假))

{

posted = true;

__doPostBack(''btnSend:'',''onclick'' );

}


}

< / script>

我认为我的问题是要么没有正确指定eventTarget或eventArgument

。有人可以指点一下吗。


很多人不知道

I have message entry screen that''s causing me a bit of an issue. At the
moment, there are 2 buttons, one is used to send message to another user
(btnSend) and another is used to send messages to all users (btnSendAll).

When user hits enter, I also simulate the effect of clicking button
(btnSend). However, what I found btnSend doesn''t fire (unless I click on the
button).

The postback function I call is as follows:
function __doPostBack(eventTarget, eventArgument)
{
var theform;
if (window.navigator.appName.toLowerCase().indexOf("n etscape") > -1)
{
theform = document.forms["Form1"];
}
else
{
theform = document.Form1;
}
theform.submit();
}

The script used to cause a postback is as follows:
<script language="javascript">
var mykey;
var posted=false;

if (window.Event){
document.captureEvents(Event.KEYDOWN);
}

document.onkeydown = myKeyDown;

function myKeyDown(e){

if (window.Event){
mykey = e.which;
}
else{
mykey = event.keyCode;
}
//alert(mykey);
if ((mykey==13) && (posted==false))
{
posted=true;
__doPostBack(''btnSend:'',''onclick'');
}

}
</script>
I think my problem is either not specifying eventTarget or eventArgument
correctly. Can someone please give a pointer on this.

Many thanx

推荐答案



你好CW,


我不明白要求在客户端上接收回发事件

方。无论如何,你可以尝试的是点击在这样的按钮里面

myKeyDown手动:

bntSend.click();


将按钮定义为提交按钮,然后它会自动回发

,你不必抓住回发事件。在任何情况下,为什么你不用

使用asp:按钮?


希望这会有所帮助,


Ethem


" CW"写道:

Hi CW,

I don''t understand the requirement to catch the postback event on the client
side. Anyway, what you can try is to "click" on the button like this inside
the myKeyDown manually:
bntSend.click();

Define your button as a submit button, then it will automatically postback
and you don''t have to catch the postback event. In any case, why don''t you
use an asp:button?

Hope this helps,

Ethem

"CW" wrote:
我有消息输入屏幕,这引起了我一些问题。在
时刻,有2个按钮,一个用于向另一个用户发送消息
(btnSend),另一个用于向所有用户发送消息(btnSendAll)。
当用户点击进入时,我也会模拟点击按钮的效果
(btnSend)。但是,我发现btnSend并不会触发(除非我点击
按钮)。

我调用的回发函数如下:
函数__doPostBack(eventTarget, eventArgument)
{
var theform;
if(window.navigator.appName.toLowerCase()。indexOf(" n etscape")> -1)
{
theform = document.forms [" Form1"];
}

{
theform = document.Form1;
}
表格。 submit();
}

用于引发回发的脚本如下:
< script language =" javascript">
var mykey;
var posted = false;

if(window.Event){
document.captureEvents(Event.KEYDOWN);
}

document.onkeydown = myKeyDown;

函数myKeyDown(e){

if(window.Event){
mykey = e.which;
}
其他{
mykey = event.keyCode;
}
// alert(mykey);
if((mykey == 13)&& (发布==假))
{
发布= true;
__ doPostBack(''btnSend:'',''onclick'');
}

}
< / script>

我认为我的问题是要么没有正确指定eventTarget或eventArgument
。有人可以指点一下。

很多人不知道
I have message entry screen that''s causing me a bit of an issue. At the
moment, there are 2 buttons, one is used to send message to another user
(btnSend) and another is used to send messages to all users (btnSendAll).

When user hits enter, I also simulate the effect of clicking button
(btnSend). However, what I found btnSend doesn''t fire (unless I click on the
button).

The postback function I call is as follows:
function __doPostBack(eventTarget, eventArgument)
{
var theform;
if (window.navigator.appName.toLowerCase().indexOf("n etscape") > -1)
{
theform = document.forms["Form1"];
}
else
{
theform = document.Form1;
}
theform.submit();
}

The script used to cause a postback is as follows:
<script language="javascript">
var mykey;
var posted=false;

if (window.Event){
document.captureEvents(Event.KEYDOWN);
}

document.onkeydown = myKeyDown;

function myKeyDown(e){

if (window.Event){
mykey = e.which;
}
else{
mykey = event.keyCode;
}
//alert(mykey);
if ((mykey==13) && (posted==false))
{
posted=true;
__doPostBack(''btnSend:'',''onclick'');
}

}
</script>
I think my problem is either not specifying eventTarget or eventArgument
correctly. Can someone please give a pointer on this.

Many thanx



你好CW,


您是否希望提供与默认按钮类似的功能?在

winform应用程序?如果是这样,通常我们可以在输入消息之前为用户输入消息的输入字段添加onkeydown

脚本。

以下是新闻组中讨论此问题的一些前线程,

你可以看看:

http://groups.google.com/groups?hl=e...2988% 40cpmsftn

gxa10.phx.gbl& rnum = 6& prev = / groups%3Fq%3Dasp.net%2Bdefault%2Bbutton%2Bsteven%

2Bcheng% 26hl%3Den

http://groups.google.com/groups?hl=e...1992%40cpmsftn

gxa07.phx.gbl& rnum = 8& prev = /groups%3Fq%3Dasp.net%2Bdefault%2Bbutton%2Bsteven%

2Bcheng%26hl%3Den


希望有所帮助。谢谢。


问候,


Steven Cheng

微软在线支持


安全! www.microsoft.com/security

(此帖子按原样提供,不作任何保证,并且不授予

权利。)

Hi CW,

Are you wanting to provide a function just like the "Default Button" in
winform application? If so, generally we can just add the "onkeydown"
script for the entryfield where the user will enter messages before he
submit.
Here are some former threads in the newsgroup discussing on this qustion,
you may have a look:

http://groups.google.com/groups?hl=e...2988%40cpmsftn
gxa10.phx.gbl&rnum=6&prev=/groups%3Fq%3Dasp.net%2Bdefault%2Bbutton%2Bsteven%
2Bcheng%26hl%3Den

http://groups.google.com/groups?hl=e...1992%40cpmsftn
gxa07.phx.gbl&rnum=8&prev=/groups%3Fq%3Dasp.net%2Bdefault%2Bbutton%2Bsteven%
2Bcheng%26hl%3Den

Hope helps. Thanks.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)


他们是asp.net实际上是按钮。


我需要捕获回车,以便它在不同的
浏览器上具有相同的行为,而不仅仅是IE。


btnSend.click适用于IE,但不适用于Netscape或Mozilla。


Thanx

" Ethem Azun" <的Et ******* @ discussions.microsoft.com>在消息中写道

新闻:6A ********************************** @ microsof t.com ...
They are asp.net buttons actually.

I need to catch enter so that it would have the same behaviour on different
browsers, not just IE.

btnSend.click works on IE, but does not work on Netscape or Mozilla.

Thanx
"Ethem Azun" <Et*******@discussions.microsoft.com> wrote in message
news:6A**********************************@microsof t.com...

你好CW,

我不明白在
客户端上捕获回发事件的要求<边。无论如何,你可以尝试的是点击在这样的按钮上面
手动myKeyDown:
bntSend.click();

将按钮定义为提交按钮,然后它会自动回发<你不必抓住回发事件。无论如何,为什么你不使用asp:按钮?

希望这会有所帮助,

Ethem

; CW"写道:

Hi CW,

I don''t understand the requirement to catch the postback event on the
client
side. Anyway, what you can try is to "click" on the button like this
inside
the myKeyDown manually:
bntSend.click();

Define your button as a submit button, then it will automatically postback
and you don''t have to catch the postback event. In any case, why don''t you
use an asp:button?

Hope this helps,

Ethem

"CW" wrote:
我有消息输入屏幕,这引起了我一些问题。在
时刻,有2个按钮,一个用于向另一个用户发送消息
(btnSend),另一个用于向所有用户发送消息(btnSendAll)。
当用户点击进入时,我也会模拟点击按钮的效果
(btnSend)。但是,我发现btnSend并没有发射(除非我点击
按钮)。

我调用的回发函数如下:
函数__doPostBack(eventTarget,eventArgument)
{
var theform;
if(window.navigator.appName.toLowerCase()。indexOf(" n etscape")> -1)
{
theform = document.forms [" Form1"];
}

{
theform = document.Form1;
}
theform.submit();
}
用于引发回发的脚本如下:
< script language =" javascript">
var mykey;
var posted = false;

if(window.Event){
document.captureEvents(Event.KEYDOWN);
}

document.onkeydown = myKeyDown;

函数myKeyDown(e){

if(window.Event){
mykey = e.which;
}
其他{
mykey = event.keyCode;
}
// alert(mykey);
if((mykey == 13)&& (发布==假))
{
发布= true;
__ doPostBack(''btnSend:'',''onclick'');
}

}
< / script>

我认为我的问题是要么没有正确指定eventTarget或eventArgument
。有人可以指点一下。

许多人不知道
I have message entry screen that''s causing me a bit of an issue. At the
moment, there are 2 buttons, one is used to send message to another user
(btnSend) and another is used to send messages to all users (btnSendAll).

When user hits enter, I also simulate the effect of clicking button
(btnSend). However, what I found btnSend doesn''t fire (unless I click on
the
button).

The postback function I call is as follows:
function __doPostBack(eventTarget, eventArgument)
{
var theform;
if (window.navigator.appName.toLowerCase().indexOf("n etscape") > -1)
{
theform = document.forms["Form1"];
}
else
{
theform = document.Form1;
}
theform.submit();
}

The script used to cause a postback is as follows:
<script language="javascript">
var mykey;
var posted=false;

if (window.Event){
document.captureEvents(Event.KEYDOWN);
}

document.onkeydown = myKeyDown;

function myKeyDown(e){

if (window.Event){
mykey = e.which;
}
else{
mykey = event.keyCode;
}
//alert(mykey);
if ((mykey==13) && (posted==false))
{
posted=true;
__doPostBack(''btnSend:'',''onclick'');
}

}
</script>
I think my problem is either not specifying eventTarget or eventArgument
correctly. Can someone please give a pointer on this.

Many thanx



这篇关于回发模拟按钮单击的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆