Problem with default button

  • Thread starter Thread starter Morten
  • Start date Start date
M

Morten

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
 
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>
 
Hi!

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

Best regards

Morten
 
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
 
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
 
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
 
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
 
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>
 
Back
Top