473,385 Members | 1,528 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Problem with default button

Hi!

I have a problem that's driving me nuts:

I have a webform with a user control containing a number of buttons at the
top. On my form I have a search button that I want to be the default
button - so that if you type something into one of the fields on my form and
hit <Return> this button is activated. I have made sure that the
"TextChanged" method of the input field of my form should trigger a search
button click.

The problem is that if I hit the <Return> key I always trigger the first
button of my user control - an ImageButton control.

Does anyone have a suggestion that will help me change this behaviour?

Thanks in advance.

Morten
Nov 20 '05 #1
7 1206
Hi Morton,

Can you try this and tell if it works with a button too?
(It works with a textbox).

I did not try it with the button until now

Cor

It need to added in the HTML, the most things are possible with register
script however as far as I know this one not.

//This should be the last rows in your html aspx file
<script language="JavaScript">
Button1.focus();
</script>
</HTML>
Nov 20 '05 #2
Hi!

Thanks for your reply. Unfortunately I couldn't make your suggestion work.

Best regards

Morten

"Cor Ligthert" <no**********@planet.nl> wrote in message
news:O1**************@tk2msftngp13.phx.gbl...
Hi Morton,

Can you try this and tell if it works with a button too?
(It works with a textbox).

I did not try it with the button until now

Cor

It need to added in the HTML, the most things are possible with register
script however as far as I know this one not.

//This should be the last rows in your html aspx file
<script language="JavaScript">
Button1.focus();
</script>
</HTML>

Nov 20 '05 #3
Hi Morton,

I thought you did want to set a button as default.
Which not even is possible I see now.

However you can archieve more simple your sollution when you set your
textboxes all with the option *autopostback* and create one sub, with as
eventhandlers textboxX.textChanged for all textboxes you want to use for
that.

If something is unclear, feel free to ask that.

Cor
Nov 20 '05 #4
Hi again!

I can't quite seem to make it work. I have a text field called
TicketSearchField , some check boxes and a drop-down. The button I'm hoping
to activate by means of hitting the <Return> key is called SearchSupport.
I've set the properties of TicketSearchField to "AutoPostBack = True". I've
also added an event handler for the text field that looks like this:
Private Sub TicketSearchField_TextChanged(ByVal sender As Object, ByVal e As
System.EventArgs) Handles TicketSearchField.TextChanged

SearchSupport_Click(sender, e)

End Sub

I would have thought that this was all I need to do but for some reason the
wrong button is activated:-(

Best regards

Morten

"Cor Ligthert" <no**********@planet.nl> wrote in message
news:uC**************@tk2msftngp13.phx.gbl...
Hi Morton,

I thought you did want to set a button as default.
Which not even is possible I see now.

However you can archieve more simple your sollution when you set your
textboxes all with the option *autopostback* and create one sub, with as
eventhandlers textboxX.textChanged for all textboxes you want to use for
that.

If something is unclear, feel free to ask that.

Cor

Nov 20 '05 #5
Hi Morten,

My problem is to understand you, why do you need a button?
The Enter itself acts already as a button.

When you want, you can add the handler to the same event as the handler from
the button.

When you are not using the "sender" and the eventargument, than you can do
in the checkbox change event something as

textboxvalue changed event
mysub(nothing,nothing)
(there are better ways, however to show you a simple method.

What do I miss?

Cor
Nov 20 '05 #6
Hi again!

I have a user control at the top of my form containing 5 buttons that people
use for various purposes. It's one of these buttons that always gets
activated when I click <Enter>. I don't think it'll change anything if I
remove my search button. As you can see from the code I posted yesterday I
already have an event handler for the textbox control and it's supposed to
emulate a click of the search button.

I probably don't understand what you're trying to say. Can you perhaps
provide a code sample?

Best regards

Morten

"Cor Ligthert" <no**********@planet.nl> wrote in message
news:OY**************@TK2MSFTNGP11.phx.gbl...
Hi Morten,

My problem is to understand you, why do you need a button?
The Enter itself acts already as a button.

When you want, you can add the handler to the same event as the handler from the button.

When you are not using the "sender" and the eventargument, than you can do
in the checkbox change event something as

textboxvalue changed event
mysub(nothing,nothing)
(there are better ways, however to show you a simple method.

What do I miss?

Cor

Nov 20 '05 #7
Hi Morten,

This should go.
'All webform controls,
'One Button (or more if you wish)
'A label and a Textbox on the page
\\\
Private Sub Page_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Me.TextBox1.AutoPostBack = True 'this always
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
Search()
End Sub
Private Sub TextBox1_TextChanged(ByVal sender As _
System.Object, ByVal e As System.EventArgs) _
Handles TextBox1.TextChanged
Search()
End Sub
Private Sub Search()
Me.Label1.Text = Me.TextBox1.Text
End Sub
///
I hope this helps?

Cor

And this in the end of your HTML than it looks real nice

</form>
<script language="JavaScript">
document.all("TextBox1").focus();
</script>
</body>
</HTML>
Nov 20 '05 #8

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

Similar topics

10
by: Hautzendorfer | last post by:
Hello, I'm currently working on some printing stuff: I have to print out several .xml files using a stylesheet. Therefor I choose the Internetexplorer PlugIn via SHDocVW. My problem: After...
0
by: Shixx | last post by:
Hello, I have problem in my web application and my web form. I have 5-6 buttons (web controls) and when I have focus on some text box, always one button becomes default and got focus, and after I...
3
by: VIJAY KUMAR | last post by:
Hi pals, I am using 2 web forms (pages). In first page, i have Datagrid control and on second page i have a hyper link control to the first page and Add value to the data grid/Database. ...
2
by: Chris Bolus | last post by:
I'm a teacher using MS Access on an RMConnect 2.4 network. On some workstations both I and my students sometimes get an error message when attempting to insert a command button on a form which...
0
by: Hypo | last post by:
Now, im still beginner with asp.net, and i picked up a problem that looked trivial at the beginning, but its not. I asked before on this newsgroup and im still not sure what to do... I have...
3
by: Michael Johnson Jr. | last post by:
The problem is the following pseudo code causes you need to click buttons twice to get event. This is notable via debugging and single stepping. I can't seem to quite figure out how to do...
1
by: Kris van der Mast | last post by:
Hi, been a while since I posted a question myself instead of trying to help others out. I'm refactoring an existing web app that uses dynamic loading of user controls and a lot of...
30
by: dbuchanan | last post by:
ComboBox databindng Problem == How the ComboBox is setup and used: My comboBox is populated by a lookup table. The ValueMember is the lookup table's Id and the DisplayMember is the text from a...
2
by: sorobor | last post by:
dear sir .. i am using cakephp freamwork ..By the way i m begener in php and javascript .. My probs r bellow I made a javascript calender ..there is a close button ..when i press close button...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.