postback when enter key?

J

jobs

asp.net 2.0.

I've got a web form when focused on a certain textboxes and i hit
enter, I want the page to postback to a particular event where I can
test textbox values.

I've tried a hidden default button with an event tied to it.. did not
work.

I've tried setting useSubmitBehavior on the button.



<form defaultfocus="TextBox_Search1" defaultbutton="Submit"
id="form1" runat="server">

<asp:TextBox ID="TextBox_Search1" runat="server" Width="214px"></
asp:TextBox>

<asp:Button ID="Submit" UseSubmitBehavior="True" Visible="False"
runat="server" Text="Button" />


Protected Sub Submit_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Submit.Click
If TextBox_Search1.Text <> "" Then
TitleSearch()
End If
End Sub

I've tried settign autopostpack on the textboxes, but then it post
when any change is made to the textbox and I tab around.

Thanks for any help or information.
 
M

Mark Rae [MVP]

I've tried a hidden default button with an event tied to it.. did not
work.

That's right - when you set a webcontrol's Visible property to "false", it
doesn't even get rendered to the client...
I've tried setting useSubmitBehavior on the button.

See above...
<asp:Button ID="Submit" UseSubmitBehavior="True" Visible="False"
runat="server" Text="Button" />

<asp:Button ID="Submit" runat="server" Text="Button" OnClick="Submit_Click"
/>
 
J

jobs

Thanks. makes sense. Any way to tie the enter key to any other
control. I have an asp.menu 2.0 in that form. It would be great if
ENTER defaulted as a click to one of the menu items. possible?

I'll need to research, but if you know off hand, possible to set a
menu item to visible = false in the codebehind?
 
M

Mark Rae [MVP]

Thanks. makes sense. Any way to tie the enter key to any other
control. I have an asp.menu 2.0 in that form. It would be great if
ENTER defaulted as a click to one of the menu items. possible?

Not using the "wired-up" method, as that only supports buttons...
I'll need to research, but if you know off hand, possible to set a
menu item to visible = false in the codebehind?

MenuItems don't have a Visible property - however:

MyMenu.Items.Remove(MyMenu.FindItem("Customers"));

or

MyMenu.FindItem("Customers").ChildItems.Remove At(1);
 

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,763
Messages
2,569,563
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top