473,471 Members | 1,898 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Wrong Form Submit

I have two forms on a page, one for logging in a user and a second one to
search thesite. The problem is, when i enter data into the search and hit
enter, it activates the login button. I need to know how to associate a
textbox with a particular button.
<asp:TextBox ID="keyword" Runat=server ></asp:TextBox>
<asp:imagebutton OnCommand="runSearch" id="runbutton" Runat=server />

so when the focus is on keyword and I hit enter, it will run "runSearch" and
not other command on other buttons.

Cheers

Rob
Nov 19 '05 #1
3 1828
You'll probably want to capture the ENTER key to prevent this. Itg isn't a
matter of clicking a button when ENTER is pressed. ENTER submits the form in
most browsers. You can use JavaScript to capture the ENTER key.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Neither a follower
nor a lender be.

"P1ayboy" <P1*****@discussions.microsoft.com> wrote in message
news:D6**********************************@microsof t.com...
I have two forms on a page, one for logging in a user and a second one to
search thesite. The problem is, when i enter data into the search and hit
enter, it activates the login button. I need to know how to associate a
textbox with a particular button.
<asp:TextBox ID="keyword" Runat=server ></asp:TextBox>
<asp:imagebutton OnCommand="runSearch" id="runbutton" Runat=server />

so when the focus is on keyword and I hit enter, it will run "runSearch" and not other command on other buttons.

Cheers

Rob

Nov 19 '05 #2
This can get a bit tangled. You can set a default button for a certain page
state, but this, by itself, will not solve your issue, as you also require
the login to work in a similar manner (or that is my assumption).

One option (a bit kludgy) is to handle both buttons with the same event and
test the sender object passed in to determine how to handle.

You can also take control of the submission in client side JavaScript, but
that makes the app harder to maintain, as you circumvent the built in
abilities of ASP.NET.

I would venture the best solution is moving away from having the login on
the form and moving it to another page. This is more inline with the ASP.NET
methodology and allows you to force logon for certain pages rather easily.
You can go to a link instead when you do that.

I have created many "multiple form" forms (actually one form with specific
controls visible at any one time). Setting the default button is as easy as
adding a handler in your code behind (do not have a snippet readily available
right now, but I can post later). As mentioned, this is a non-solution for
you, as your form has two forms showing at once.

---

Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

***************************
Think Outside the Box!
***************************
"P1ayboy" wrote:
I have two forms on a page, one for logging in a user and a second one to
search thesite. The problem is, when i enter data into the search and hit
enter, it activates the login button. I need to know how to associate a
textbox with a particular button.
<asp:TextBox ID="keyword" Runat=server ></asp:TextBox>
<asp:imagebutton OnCommand="runSearch" id="runbutton" Runat=server />

so when the focus is on keyword and I hit enter, it will run "runSearch" and
not other command on other buttons.

Cheers

Rob

Nov 19 '05 #3
Thanks Gregory,

Unfortunately, its a set design that I have to adhere to, which means both
forms MUST appear on the page. Bloody designers huh!

Looks like I might have to run some javascipt for it!

Thanks again.

"Cowboy (Gregory A. Beamer) - MVP" wrote:
This can get a bit tangled. You can set a default button for a certain page
state, but this, by itself, will not solve your issue, as you also require
the login to work in a similar manner (or that is my assumption).

One option (a bit kludgy) is to handle both buttons with the same event and
test the sender object passed in to determine how to handle.

You can also take control of the submission in client side JavaScript, but
that makes the app harder to maintain, as you circumvent the built in
abilities of ASP.NET.

I would venture the best solution is moving away from having the login on
the form and moving it to another page. This is more inline with the ASP.NET
methodology and allows you to force logon for certain pages rather easily.
You can go to a link instead when you do that.

I have created many "multiple form" forms (actually one form with specific
controls visible at any one time). Setting the default button is as easy as
adding a handler in your code behind (do not have a snippet readily available
right now, but I can post later). As mentioned, this is a non-solution for
you, as your form has two forms showing at once.

---

Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

***************************
Think Outside the Box!
***************************
"P1ayboy" wrote:
I have two forms on a page, one for logging in a user and a second one to
search thesite. The problem is, when i enter data into the search and hit
enter, it activates the login button. I need to know how to associate a
textbox with a particular button.
<asp:TextBox ID="keyword" Runat=server ></asp:TextBox>
<asp:imagebutton OnCommand="runSearch" id="runbutton" Runat=server />

so when the focus is on keyword and I hit enter, it will run "runSearch" and
not other command on other buttons.

Cheers

Rob

Nov 19 '05 #4

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

Similar topics

9
by: Bartosz Wegrzyn | last post by:
I need help with sessions. I createt set of web site for nav with authorization. first I go into main.php which looks like this: <?php //common functions include_once '../login/common.php';...
6
by: Andre | last post by:
Hi, I need to fetch a value in an Access db, so i use a form to pass the parameter for the SQL statement fromVB client to ASP. After the submit line in VBscript, i expect the value in order to...
6
by: Rtritell | last post by:
Please can you find out what's wrong, fix the script and tell me what was wrong. Im just beginning <html> <head> <title>Random Mad Lib!</title> <script language="JavaScript"> <!-- Hide
5
by: Werner Partner | last post by:
On my testpage http://www.sonoptikon.de/test.php I have this <table><tr> <td valign="top" align="center" style="width:150px;"> <form action=test.php method="get">
4
by: karenmiddleol | last post by:
I have a simple form to accept two form fields and display the values entered on pressing the submit button. The following is the form I have created to accept the two entries and display the form...
8
by: bdobby | last post by:
Hi. I am relatively new to js, but I did think I was starting to get the hang of it. Then this happened... I have a form with an onsubmit event handler: <form id="uploadForm" method="post"...
3
by: snowweb | last post by:
I'm creating my first web application in PHP/MySQL, however, when I go to view the database contents, the data has been stored in the wrong columns. I've gone through my insertion code with a fine...
2
by: firstexact | last post by:
Hi guys, First post, hope you can help, I have done two sites www.trisant.co.uk and my own www.firstexact.co.uk. The 2 x 2 grid I originally envisaged goes haywire in Firefox as I get a 4 high by...
2
by: TheSouthLondonSlasher | last post by:
Thank you in advance to anyone who may be able to help. This is my first attempt at JavaScript, so I apologize if I've done something blatantly stupid in the below code. Basically, I have a form...
0
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,...
0
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...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
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,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
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 ...

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.