Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 408237
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T17:40:23+00:00 2026-05-12T17:40:23+00:00

i have a textbox on my form with a linkbutton next to it. the

  • 0

i have a textbox on my form with a linkbutton next to it.
the textbox’ id is textbox1 and the linkbutton is lbSearch

in the page_load event i add:

  this.TextBox1.Attributes.Add("onkeydown", "if(event.which || event.keyCode)
        {
            if ((event.which == 13) || (event.keyCode == 13))                              
            {
                document.getElementById('" + this.lbSearch.ClientID + "').click();
                return false;
            }
        }
        else 
        {
            return true
        }; ");

and in firefox this works but in internet explorer it doesn’t

this is because the linkbutton get’s rendered as

     <a href="..."

how can i resolve this?

without changing the linkbutton to an imagebutton or regular button.

the linkbutton gets rendered like this:

    <a href='javascript:WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions("ctl00$zoeken1$lbSearch", "", true, "search", "", false, true))' id="ctl00_zoeken1_lbSearch">zoek</a>

edit: i tried the following and received the following message:

function onkeydown does not always return a value
rule: 1, column: 243

source:


if(event.which || event.keyCode)
{
if ((event.which == 13) || (event.keyCode == 13)) 
{ 
    var link = document.getElementById('ctl00_zoeken1_lbSearch'); 
    __doPostBack(link.id.replace('_','$'),''); 
    return false;
}
else
{
    return true;
}
} 
else
{
return true;
}; 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T17:40:23+00:00Added an answer on May 12, 2026 at 5:40 pm

    You would be better off detecting the enter key using the keypress rather than keydown event, and it would be better to use a function rather than a long piece of code in an attribute. Also if you want to prevent the default action you’ll need to return false in the onkeypress attribute, as below.

    <script type="text/javascript">
    
    function checkEnterPressed(evt, linkButtonId) {
        var charCode = evt.keyCode || evt.which;
        if (charCode == 13) {
            // Do the LinkButton stuff here...
            return false;
        }
        return true;
    }
    
    </script>
    
    
    this.TextBox1.Attributes.Add("onkeydown",
        "return checkEnterPressed(event, '" + this.lbSearch.ClientID + "')");
    

    Doing the search and replace on the ID to get the value to pass to __doPostBack seems hopelessly brittle and hacky. I really think you should find another way. Can you get hold of that value ctl00$zoeken1$lbSearch from the this.lbSearch LinkButton object somehow?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a TextBox control on my Form. I use the Leave event on
Say I have a Textbox nested within a TabControl . When the form loads,
I have several ASP:TextBox controls on a form (about 20). When the form loads,
I have a form with a textbox and a button. IE is the only
I have a really simple search form with the following Label (Search) Textbox (fixed
If I have .Net Form with a component/object such as a textbox that I
I have a bunch of controls (textbox and combobox) on a form with toolstripcontainer
I have three TextBox controls on the page <asp:TextBox ID=TextBox1 runat=server AutoPostBack=True OnTextChanged=TextBox_TextChanged TabIndex=1>
In my application I have TextBox in a FormView bound to a LinqDataSource like
I have a textbox whose input is being handled by jQuery. $('input.Search').bind(keyup, updateSearchTextbox); When

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.