multiple submit buttons -- controlling default button

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • thersitz

    #1

    multiple submit buttons -- controlling default button

    Hi,

    Using aspnet3.5,VStud io 2008, VB

    1.) I have a set of pages, with a search text box button within a
    userControl that searches across our websites and is registered in a
    masterpage.

    2) Also within that set of pages, I have a second, distinct seach box and
    button that searches a specific database that is within an asp:content area
    which inherits said masterpage

    The problem is when using the enter key on the text box belonging to #2 --
    it defaults to the submit button loaded into #1 and takes the user to the
    wrong place.

    Any way, I've googled and tried a number of things but no real success and
    am hoping someone can point me to the cleanest, best approach to using 2
    separate textbox/button instances, designed to search different data stores.
    Below are some things I have tried. Thanks for any help.

    I tried placing this in the content page code behind:

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As
    System.EventArg s) Handles Me.Load
    Page.Form.Defau ltFocus = CISOBOX1.Client ID
    Page.Form.Defau ltButton = Button1.UniqueI D
    End Sub

    This basically reversed the problem. When the page loads, the #2 submit
    becomes the default button and using the enter key in #1 jumps the user to
    the wrong page.

    I tried wrapping the asp:content search combo in a <asp:panel runat=server
    defaultbutton=B utton1and then adding the userControl button as the
    defaultbuttonin my <form ...tag within my masterpage -- but then I get
    this error:

    The DefaultButton of 'form1' must be the ID of a control of type
    IButtonControl.

    I tried adding this javascript in the <head ></head>of my masterpage and
    then add the approriate event handler to the respective text boxes -- but
    nothing

    <script language="javas cript">
    function KeyDownHandler( btn)
    {
    // process only the Enter key
    if (event.keyCode == 13)
    {
    // cancel the default submit
    event.returnVal ue=false;
    event.cancel = true;
    // submit the form by programmaticall y clicking the specified
    button
    btn.click();
    }
    }
    </script>


Working...