Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Master Page, Logout control & Enter key behavior 1

Status
Not open for further replies.

markros

Programmer
May 21, 2007
3,150
US
Hi,

We're experiencing strange behavior in one of our pages. When we put a cursor in any of the Search fields and press Enter button, the Logout fires and the Login page displays. I would prefer Enter to fire Search button click, or do it only after I entered at least one character in the Search fields (otherwise don't do anything).

We have a similar page in our application, where the JavaScript code is added in the Load method of the page using ClientScriptManager.RegisterStartuptScript method. This JavaScript checks for the Enter key
Code:
string Script = @"<script language=""javascript""> 
        // make sure that when enter clicked click event fired.
        function testEnterKey(event) 
        {     
            if (event.keyCode == 13) 
            {
                var btnSearch = document.getElementById('" + this.btnSearch.ClientID + @"');
                event.cancelBubble = true; 
                event.returnValue = false;
                btnSearch.click(); 
            } 
        } 
    </script>";

Then in OnPreRender event for the textboxes the OnKeyChange attribute is added to call this function.

This code works fine in one of the pages. However, I tried to implement the same logic for another page and OnPreRender never fires.

Do you have ideas how to fix the problem and how to stop Logout code firing by pressing Enter?

Thanks.
 
If you are using v2.0 or later of the framework, then you can do this:
Code:
<form id="form1" runat="server" [blue]defaultbutton="btnSearch"[/blue]>
   .... your stuff here
</form>
 
In our case we're using Master page. Where should I try to put the defaultbutton for the content page? (The page we're working on)?
 
Put it on the content page or usercontrol that holds the button you want as the default.
 
It worked after I put search controls in a Panel and added DefaultButton.

Thanks.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top