Click here to Skip to main content
15,908,274 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
XML
<script language="javascript" type="text/javascript">
    //the purpose of this function is to allow the enter key to
    function doClick(buttonName, e) {
        var key;
        if (window.event)
            key = window.event.keyCode;     //IE
        else
            key = e.which;     //firefox
        if (key == 13) {
            var btn = document.getElementById(buttonName);
            if (btn != null) { //If we find the button click it
                btn.click();
                event.keyCode = 0
            }
        }
    }

</script>

----------------------------*******-------------------------------
C#
protected void Page_Load(object sender, EventArgs e)
  {
     // if (!IsPostBack)
      if (!this.IsPostBack)
      {
          Control myLoginButton = Login1.FindControl("LoginButton");
          if (myLoginButton != null && myLoginButton is IButtonControl)
          {
              Login1.Attributes.Add("onKeyPress", "doClick('" + myLoginButton.ClientID + "',event)");
          }
      }
  }

Posted
Updated 15-Apr-11 23:26pm
v3
Comments
tulasiram3975 16-Apr-11 4:07am    
Could You Please Elaborate Clearly
saqib786 16-Apr-11 4:13am    
When I enter login In Button They goes to next page..
but they work properly in Google Chrome ,Internet Explorer..
saqib786 16-Apr-11 5:25am    
When Execute My Website if i have to enter ID and Password in login page then press Enter Button They open New Window In (Fire Fox Browser)
But they Work Properly in Internet Explore , Google Chrome

1 solution

Instead of doing this, just set the default button of your form to the button you want to click when enter is pressed.
Something like this:

XML
<form id="form1" runat="server" defaultbutton="LoginButton">

</form>


Hope this helps!
 
Share this answer
 
Comments
saqib786 16-Apr-11 5:42am    
Sir i am working on Asp.net Page so what did the meaning of[ <form id="form1" runat="server" defaultbutton="LoginButton">]
Ankur\m/ 16-Apr-11 5:48am    
Every HTML (ASP.NET) page has at least one form element.
Check your aspx page. You will have a form element just below the BODY tag. Add the code I have given, and your purpose will be solved.
You seem to be a beginner in this technology. I suggest you to spend some time reading some books on ASP.NET (and HTML) before you start programming.
saqib786 16-Apr-11 5:51am    
thanks for advices but exception is appeared when i apply your logic..
Be Respective
Ankur\m/ 16-Apr-11 5:59am    
but exception is appeared when i apply your logic..
What exception?
Be Respective
Wasn't I polite? You do not know about a form element which is the most basic thing of a web page and so I was trying to help you out in the long run, but it seems you do not like good advices. I must tell you that people here are very rude when you DEMAND something. Try to learn as much as possible. Use Google! Show you have put in some effort and then ask. Hope that makes sense to you.
saqib786 16-Apr-11 6:13am    
i know you just copy paste from Google sorry to say its not a help.
i am create own my logic..
i have also took a help from Google then post my Question.
i have so much sense......

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900