postback when enter key?

Discussion in 'ASP .Net' started by jobs, Jul 15, 2007.

  1. jobs

    jobs Guest

    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.
     
    jobs, Jul 15, 2007
    #1
    1. Advertising

  2. "jobs" <> wrote in message
    news:...

    > 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"
    />


    --
    Mark Rae
    ASP.NET MVP
    http://www.markrae.net
     
    Mark Rae [MVP], Jul 15, 2007
    #2
    1. Advertising

  3. jobs

    jobs Guest

    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?
     
    jobs, Jul 15, 2007
    #3
  4. "jobs" <> wrote in message
    news:...

    > 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);


    --
    Mark Rae
    ASP.NET MVP
    http://www.markrae.net
     
    Mark Rae [MVP], Jul 16, 2007
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?am9l?=
    Replies:
    0
    Views:
    736
    =?Utf-8?B?am9l?=
    Sep 28, 2006
  2. BrianDH

    Enter Key H*ll, control enter key submit button

    BrianDH, Jan 12, 2005, in forum: ASP .Net Web Controls
    Replies:
    3
    Views:
    404
    Anders Matthiessen
    Jan 12, 2005
  3. M P
    Replies:
    1
    Views:
    485
  4. Matt
    Replies:
    1
    Views:
    511
    Michael Winter
    Mar 6, 2004
  5. HopfZ
    Replies:
    0
    Views:
    576
    HopfZ
    Aug 28, 2006
Loading...

Share This Page