473,809 Members | 2,719 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

issue with click on button

Hi,
I've written some javascript function so that if a textbox has the
focus and the user press enter, it triggers a click on a button
'associated' to this textbox (see code at the end)
The javascript works fine. If I'm in txtJournalist2 and I press enter,
the OnClick Server event of btnAuthor2 is triggered. But the problem is
that for some reason, the OnClick Server event of btnAuthor is also
triggered afterward (not from the javascript as no alert popup is
shown).

In fact if I invert the place of the buttons in the page, so that
btnAuthor2 is BEFORE btnAuthor then there is always a call to the
OnClick event of btnAuthor2 even if I was in the first textbox when I
pressed Enter......

Does anyone know why ?

Thanks

<asp:TextBox ID="txtJournali st" runat="server" onkeypress="fct (event,
this);"></asp:TextBox>
<asp:Button ID="btnAuthor" runat="server" Text="Search... "
CausesValidatio n="False" />

<asp:TextBox ID="txtJournali st2" runat="server" onkeypress="fct (event,
this);"></asp:TextBox>
<asp:Button ID="btnAuthor2 " runat="server" Text="Search... "
CausesValidatio n="False" />&nbsp;


function fct(evt, obj)
{
evt = (evt)? evt : event
var charCode = (evt.which) ? evt.which : evt.keyCode
if(charCode == 13)
{
if (obj.name == 'ctl00$cpBody$t xtJournalist')
{
alert('ctl00$cp Body$txtJournal ist');
document.getEle mentById("ctl00 _cpBody_btnAuth or").click();
}
else if (obj.name == 'ctl00$cpBody$t xtJournalist2')
{
alert('ctl00$cp Body$txtJournal ist2');
document.getEle mentById("ctl00 _cpBody_btnAuth or2").click();
}
else if (obj.name == 'ctl00$cpBody$t xtPublication')
{
alert('ctl00$cp Body$txtPublica tion');

document.getEle mentById("ctl00 _cpBody_btnPubl ication").click ();
}
return false;
}
else
return true;
}

Jun 6 '06 #1
3 1563
If you press enter, the first button in the form is used to post the
form. As the form is already being posted, the event sent by the click()
method is never handled.

graphicsxp wrote:
Hi,
I've written some javascript function so that if a textbox has the
focus and the user press enter, it triggers a click on a button
'associated' to this textbox (see code at the end)
The javascript works fine. If I'm in txtJournalist2 and I press enter,
the OnClick Server event of btnAuthor2 is triggered. But the problem is
that for some reason, the OnClick Server event of btnAuthor is also
triggered afterward (not from the javascript as no alert popup is
shown).

In fact if I invert the place of the buttons in the page, so that
btnAuthor2 is BEFORE btnAuthor then there is always a call to the
OnClick event of btnAuthor2 even if I was in the first textbox when I
pressed Enter......

Does anyone know why ?

Thanks

<asp:TextBox ID="txtJournali st" runat="server" onkeypress="fct (event,
this);"></asp:TextBox>
<asp:Button ID="btnAuthor" runat="server" Text="Search... "
CausesValidatio n="False" />

<asp:TextBox ID="txtJournali st2" runat="server" onkeypress="fct (event,
this);"></asp:TextBox>
<asp:Button ID="btnAuthor2 " runat="server" Text="Search... "
CausesValidatio n="False" />&nbsp;


function fct(evt, obj)
{
evt = (evt)? evt : event
var charCode = (evt.which) ? evt.which : evt.keyCode
if(charCode == 13)
{
if (obj.name == 'ctl00$cpBody$t xtJournalist')
{
alert('ctl00$cp Body$txtJournal ist');
document.getEle mentById("ctl00 _cpBody_btnAuth or").click();
}
else if (obj.name == 'ctl00$cpBody$t xtJournalist2')
{
alert('ctl00$cp Body$txtJournal ist2');
document.getEle mentById("ctl00 _cpBody_btnAuth or2").click();
}
else if (obj.name == 'ctl00$cpBody$t xtPublication')
{
alert('ctl00$cp Body$txtPublica tion');

document.getEle mentById("ctl00 _cpBody_btnPubl ication").click ();
}
return false;
}
else
return true;
}

Jun 6 '06 #2
Fair enough, but then what is the workaround ?
Göran Andersson wrote:
If you press enter, the first button in the form is used to post the
form. As the form is already being posted, the event sent by the click()
method is never handled.

graphicsxp wrote:
Hi,
I've written some javascript function so that if a textbox has the
focus and the user press enter, it triggers a click on a button
'associated' to this textbox (see code at the end)
The javascript works fine. If I'm in txtJournalist2 and I press enter,
the OnClick Server event of btnAuthor2 is triggered. But the problem is
that for some reason, the OnClick Server event of btnAuthor is also
triggered afterward (not from the javascript as no alert popup is
shown).

In fact if I invert the place of the buttons in the page, so that
btnAuthor2 is BEFORE btnAuthor then there is always a call to the
OnClick event of btnAuthor2 even if I was in the first textbox when I
pressed Enter......

Does anyone know why ?

Thanks

<asp:TextBox ID="txtJournali st" runat="server" onkeypress="fct (event,
this);"></asp:TextBox>
<asp:Button ID="btnAuthor" runat="server" Text="Search... "
CausesValidatio n="False" />

<asp:TextBox ID="txtJournali st2" runat="server" onkeypress="fct (event,
this);"></asp:TextBox>
<asp:Button ID="btnAuthor2 " runat="server" Text="Search... "
CausesValidatio n="False" />&nbsp;


function fct(evt, obj)
{
evt = (evt)? evt : event
var charCode = (evt.which) ? evt.which : evt.keyCode
if(charCode == 13)
{
if (obj.name == 'ctl00$cpBody$t xtJournalist')
{
alert('ctl00$cp Body$txtJournal ist');
document.getEle mentById("ctl00 _cpBody_btnAuth or").click();
}
else if (obj.name == 'ctl00$cpBody$t xtJournalist2')
{
alert('ctl00$cp Body$txtJournal ist2');
document.getEle mentById("ctl00 _cpBody_btnAuth or2").click();
}
else if (obj.name == 'ctl00$cpBody$t xtPublication')
{
alert('ctl00$cp Body$txtPublica tion');

document.getEle mentById("ctl00 _cpBody_btnPubl ication").click ();
}
return false;
}
else
return true;
}


Jun 6 '06 #3
Make sure that the keypress event is stopped from posting the form. IIRC
you use cancelBubble to do that.

graphicsxp wrote:
Fair enough, but then what is the workaround ?
Göran Andersson wrote:
If you press enter, the first button in the form is used to post the
form. As the form is already being posted, the event sent by the click()
method is never handled.

graphicsxp wrote:
Hi,
I've written some javascript function so that if a textbox has the
focus and the user press enter, it triggers a click on a button
'associated' to this textbox (see code at the end)
The javascript works fine. If I'm in txtJournalist2 and I press enter,
the OnClick Server event of btnAuthor2 is triggered. But the problem is
that for some reason, the OnClick Server event of btnAuthor is also
triggered afterward (not from the javascript as no alert popup is
shown).

In fact if I invert the place of the buttons in the page, so that
btnAuthor2 is BEFORE btnAuthor then there is always a call to the
OnClick event of btnAuthor2 even if I was in the first textbox when I
pressed Enter......

Does anyone know why ?

Thanks

<asp:TextBox ID="txtJournali st" runat="server" onkeypress="fct (event,
this);"></asp:TextBox>
<asp:Button ID="btnAuthor" runat="server" Text="Search... "
CausesValidatio n="False" />

<asp:TextBox ID="txtJournali st2" runat="server" onkeypress="fct (event,
this);"></asp:TextBox>
<asp:Button ID="btnAuthor2 " runat="server" Text="Search... "
CausesValidatio n="False" />&nbsp;


function fct(evt, obj)
{
evt = (evt)? evt : event
var charCode = (evt.which) ? evt.which : evt.keyCode
if(charCode == 13)
{
if (obj.name == 'ctl00$cpBody$t xtJournalist')
{
alert('ctl00$cp Body$txtJournal ist');
document.getEle mentById("ctl00 _cpBody_btnAuth or").click();
}
else if (obj.name == 'ctl00$cpBody$t xtJournalist2')
{
alert('ctl00$cp Body$txtJournal ist2');
document.getEle mentById("ctl00 _cpBody_btnAuth or2").click();
}
else if (obj.name == 'ctl00$cpBody$t xtPublication')
{
alert('ctl00$cp Body$txtPublica tion');

document.getEle mentById("ctl00 _cpBody_btnPubl ication").click ();
}
return false;
}
else
return true;
}

Jun 6 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
1938
by: Girish | last post by:
I have TWO submit buttons of type IMAGE on my asp form. This renders as <input type="image">. I need to be able to eble the ENTER button for both buttons. Yes, I know that for the input type image, the submit happens automatically to the server. Heres my problem: I have two event handlers for both these buttons as stated below: BUTTON 1:
6
1527
by: Mike | last post by:
I have a function that is called when the user clicks the submit button, during this function i also set a varaible to "Y" due to that this function does a post back to the page then redirects. When I look for the session variable in the page.isPostBack section it equals nothing, it appears that the variable is not being passed to the post back section correctly. I have this due to I only want this function to run if the user has something...
9
7801
by: PK9 | last post by:
I'm having an issue with the "Refresh" of an asp.net page. The refresh is actually calling my last onClick event. I thought that asp.net was supposed to be stateless in that it shouldn't remember that I clicked a button before the refresh. Here is what is going on: 1) Page Loads 2) User enters some values, clicks the "Save" button 3) The onClick event handler for the save button saves the data to the database and the page is...
10
2194
by: Li Pang | last post by:
Hi, I created a html page from which I give a link to another web site. The new site is opened in a new window. When I opened multiple windows, they all have the same SessionID. I want ot know how to open the windows with different sessionID. Thanks
12
2602
by: raghav | last post by:
Hi I am working on ASP.NET 2.0. I am developing a website using Wizard control. Based on number of steps added, next, previous, finish buttons generate automatically. After running the application, these button work automatically, means we can go to next step, previous step by clicking on corresponding buttons. In my application I have 3 steps. On Next button click of step 1, I want two things to happen. One is inserting data of step 1 in...
11
1818
by: =?Utf-8?B?R29rdWw=?= | last post by:
I am struck up with a problem and want anyone here to help me out. I am a beginner in .NET trying to learng DataBinding concepts. I have binded 4 text boxes with a dataset but when I say adapter.update it gives me 0 records updated! I am not getting any exceptions. Below is the complete code. Someone please help me out. using System; using System.Drawing; using System.Collections; using System.ComponentModel;
1
3804
by: =?Utf-8?B?bGpsZXZlbmQy?= | last post by:
I've noticed that controls do not raise a Validating event if they are contained in a ToolStripDropDown via a ToolStripControlHost item. Please run the following sample and follow the instructions on the form to reproduce this issue: ------------------------------------ Public Class Form1 Inherits Windows.Forms.Form
2
1408
by: Paul | last post by:
I've written som junk code below to show a problem I'm getting: On a page I've got a dropdownlist and a button using submit behaviour: <asp:DropDownList ID="tester" runat="server" AutoPostBack="true" EnableViewState="False" OnSelectedIndexChanged="tester_SelectedIndexChanged"> <asp:ListItem Text="All" Value="ALL"></asp:ListItem> <asp:ListItem Text="2" Value="2"></asp:ListItem> <asp:ListItem Text="3" Value="3"></asp:ListItem>
1
5810
by: chaitanyadotcom | last post by:
As per my application i need to create tabs using iFrame dynamically. There are totally 4 buttons in my application where for each button i provide a link. Where in it will dynamically create a tab inside the iFrame. For example.. first button contains google.com second button contains yahoo.com 3rd button contains hotmail.com if i click on first button i.e google.com , tab is created and link to google.com is generated as a tab in...
0
9721
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9602
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10639
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10376
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9200
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6881
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5688
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4332
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3861
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.