postback simulating button click

C

CW

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("netscape") > -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
 
G

Guest

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
 
S

Steven Cheng[MSFT]

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=en&lr=&threadm=25ZlQYfSEHA.2988@cpmsftn
gxa10.phx.gbl&rnum=6&prev=/groups%3Fq%3Dasp.net%2Bdefault%2Bbutton%2Bsteven%
2Bcheng%26hl%3Den

http://groups.google.com/groups?hl=en&lr=&threadm=x8Tmqg83DHA.1992@cpmsftn
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.)
 
C

CW

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 said:
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 said:
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("netscape") > -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
 
G

Guest

Hi,

I have Netscape 7.1 and the following does work (which is simply the
button.click() added to your code.). Are you sure that you are not doing
something wrong other than this? The aspnet button will be rendered as a
simple submit button.

<HTML>
<HEAD>
<title>Netscape</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema"
content="http://schemas.microsoft.com/intellisense/ie5">
<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;
this.Form1.butTest.click();
}
}
</script>
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<asp:Button id="butTest" style="Z-INDEX: 101; LEFT: 56px; POSITION:
absolute; TOP: 32px" runat="server" Text="Button" Width="96px"></asp:Button>
</form>
</body>
</HTML>

CW said:
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 said:
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 said:
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("netscape") > -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
 
C

CW

I think latest NN 7.x is fine. But the same javascript does not seem to fire
postback when run int NN 6.x and NN 4.x and Mozilla .9x.

Form1.btnSend.click() does not seem to be recognizable to them.

Ethem Azun said:
Hi,

I have Netscape 7.1 and the following does work (which is simply the
button.click() added to your code.). Are you sure that you are not doing
something wrong other than this? The aspnet button will be rendered as a
simple submit button.

<HTML>
<HEAD>
<title>Netscape</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema"
content="http://schemas.microsoft.com/intellisense/ie5">
<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;
this.Form1.butTest.click();
}
}
</script>
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<asp:Button id="butTest" style="Z-INDEX: 101; LEFT: 56px; POSITION:
absolute; TOP: 32px" runat="server" Text="Button"
Width="96px"></asp:Button>
</form>
</body>
</HTML>

CW said:
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 said:
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

:

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("netscape")
-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
 
G

Guest

How about
document.getElementById('btnSend').click();

CW said:
I think latest NN 7.x is fine. But the same javascript does not seem to fire
postback when run int NN 6.x and NN 4.x and Mozilla .9x.

Form1.btnSend.click() does not seem to be recognizable to them.

Ethem Azun said:
Hi,

I have Netscape 7.1 and the following does work (which is simply the
button.click() added to your code.). Are you sure that you are not doing
something wrong other than this? The aspnet button will be rendered as a
simple submit button.

<HTML>
<HEAD>
<title>Netscape</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema"
content="http://schemas.microsoft.com/intellisense/ie5">
<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;
this.Form1.butTest.click();
}
}
</script>
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<asp:Button id="butTest" style="Z-INDEX: 101; LEFT: 56px; POSITION:
absolute; TOP: 32px" runat="server" Text="Button"
Width="96px"></asp:Button>
</form>
</body>
</HTML>

CW said:
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



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

:

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("netscape")
-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
 
G

Guest

or
document.forms["Form1"].bntSend.click()
or even
document.forms[0].bntSend.click() ?

it quite weird if they don't work either. Can you take a look at your html
output to see the id of the button if the ones above don't work?

Jeremy Davis said:
How about
document.getElementById('btnSend').click();

CW said:
I think latest NN 7.x is fine. But the same javascript does not seem to fire
postback when run int NN 6.x and NN 4.x and Mozilla .9x.

Form1.btnSend.click() does not seem to be recognizable to them.

Ethem Azun said:
Hi,

I have Netscape 7.1 and the following does work (which is simply the
button.click() added to your code.). Are you sure that you are not doing
something wrong other than this? The aspnet button will be rendered as a
simple submit button.

<HTML>
<HEAD>
<title>Netscape</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema"
content="http://schemas.microsoft.com/intellisense/ie5">
<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;
this.Form1.butTest.click();
}
}
</script>
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<asp:Button id="butTest" style="Z-INDEX: 101; LEFT: 56px; POSITION:
absolute; TOP: 32px" runat="server" Text="Button"
Width="96px"></asp:Button>
</form>
</body>
</HTML>

:

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



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

:

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("netscape")
-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
 
G

gh0st54

HI CW

check into this
on page load add this

Page.RegisterHiddenField("__EVENTTARGET",this.<default button that you
want>.ClientID);

I use this on all pages with the javascript

what happens is that by default the page button will be what you have
set in < >

when you post back the page will look at the __EVENTTARGET field to
know with control trigged the post back



CW said:
I think latest NN 7.x is fine. But the same javascript does not seem to fire
postback when run int NN 6.x and NN 4.x and Mozilla .9x.

Form1.btnSend.click() does not seem to be recognizable to them.

Ethem Azun said:
Hi,

I have Netscape 7.1 and the following does work (which is simply the
button.click() added to your code.). Are you sure that you are not doing
something wrong other than this? The aspnet button will be rendered as a
simple submit button.

<HTML>
<HEAD>
<title>Netscape</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema"
content="http://schemas.microsoft.com/intellisense/ie5">
<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;
this.Form1.butTest.click();
}
}
</script>
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<asp:Button id="butTest" style="Z-INDEX: 101; LEFT: 56px; POSITION:
absolute; TOP: 32px" runat="server" Text="Button"
Width="96px"></asp:Button>
</form>
</body>
</HTML>

CW said:
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



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

:

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("netscape")
-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
 
S

Steven Cheng[MSFT]

Hi CW,

I think you can have a try on Jeremy's suggestion that use the
document.getElementById method to locate the submit button object. I
suspect that the problem is the submit button object is not located. The
Submit button's click() simiulate method is implement in javascript1.0 so I
think it should be support by netscape's early version.

Also, here is another blog article maybe helpful:

#Setting the default Button for a TextBox in ASP.NET
http://weblogs.asp.net/rajbk/archive/2003/12/11/43023.aspx

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.)
 
C

CW

Hi everyone

Thanks for all the suggestions and help. I managed to get it work after
abandoning button.click() method.

Eveutally, I was able to get button.click to work, however, I had to modify
the code to use document.Form1.button.click()
or document.forms["Form1"].button.click(). For some reason, not specifying
document specifier causes the code not to run on NS browsers.
 
S

Steven Cheng[MSFT]

HI CW,

Thanks for your followup and I'm glad that you figured out the problem.
Have a nice day!


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.)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,822
Latest member
israfaceZa

Latest Threads

Top