locked
button execution while pressing enter RRS feed

  • Question

  • User575197996 posted

    i Used this client-side javascript

     

     

    function clickSearch(sender, eventArgs)
    {
    var c = eventArgs.get_keyCode();
    if (c == 13){
    var bt = document.getElementById('ImgBt_Raise');
    bt.click();
    return false;
    }
    }

     
    now just add this to the SearchTextBox

     

     

    <asp:TextBox runat="server" id="txtSearchBox" OnKeyPress="clickSearch" /> 
    <asp:ImageButton id="ImgBt_Raise"........................................./> 
    But this will not be working.
    if i type some thing in textbox. and press enter button means particular imagebutton should be fired.
    but some other button only fired. i need imagebuton should be fired in pressing enter button after typing text in textbox
    pleas help me 
    Monday, May 25, 2009 12:17 AM

Answers

  • User604186779 posted

    but i am in above situation. pleas e help me.
     

    Hi , I gave the link already check it , place the searchtextbox and button on one panel and other ie: reportextbox and button should be another panel , this should work.. 

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, May 25, 2009 1:53 AM
  • User-1034726716 posted

    if i type some thing in textbox. and press enter button means particular imagebutton should be fired.
    but some other button only fired. i need imagebuton should be fired in pressing enter button after typing text in textbox

     

    Based on my understanding you want to execute the Button Click event when hitting the Enter key in the TextBox control.. If so then you can refer the following snippet below for your reference:

    ASPX Mark Up and JavaScript function

     
    <head>
    <title>Untitled Page</title>
    </style>
    <script type="text/javascript" language="javascript">

    function controlEnter (obj, event)
    {
    var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
    if (keyCode == 13)
    {
    document.getElementById(obj).click();
    return false;
    }
    else {
    return true;
    }
    }
    </script>
    </head>
    <body>
    <form id="form1" runat="server">

    <asp:TextBox ID="TextBox1" runat="server" ></asp:TextBox>
    <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" />

    </form>
    </body>
     

    RELEVANT CODES:

     
    protected void Page_Load(object sender, EventArgs e)
    {
    TextBox1.Attributes.Add("onkeypress", "return controlEnter('" + Button1.ClientID + "', event)");
    }

    protected void Button1_Click(object sender, EventArgs e)
    {
    Response.Write("Button was Clicked!");
    }

     

    You may also see:

    Forcing Button Click event to fire up when pressing ENTER Key on TextBox

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, May 25, 2009 4:07 AM

All replies

  • User604186779 posted

    i need imagebuton should be fired in pressing enter button after typing text in textbox
    pleas help me 

     

    You have make the imagebutton as default button check this

    http://venkat-dotnetsamples.blogspot.com/search/label/Default%20button

    Monday, May 25, 2009 1:38 AM
  • User575197996 posted

     friend,

    in my page,  i am having two imagebuttons. one for searching and another for report generation.

    if i want to search, i type something searchtextbox and press enter. in this situation. searching imagebutton should be fired.

    if i want to generate report, i type something report textbox and press eneter. in this situation, report imagebutton should be fired.

    i have to change firing focus on button based on  which textbox i typed.

     

    above one is working. but i am in above situation. pleas e help me.

    it is urgent

    Monday, May 25, 2009 1:47 AM
  • User604186779 posted

    but i am in above situation. pleas e help me.
     

    Hi , I gave the link already check it , place the searchtextbox and button on one panel and other ie: reportextbox and button should be another panel , this should work.. 

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, May 25, 2009 1:53 AM
  • User-151352204 posted

     you check you code with above link

    http://www.bloggingdeveloper.com/post/Default-Button-in-ASPNET-11.aspx

    if it not works check with below code


    function onKeySignin()
        {
        if (window.event.keyCode == 13)
            {
            document.getElementById('<%=Button1.ClientID%>').focus();
            document.getElementById('<%=Button1.ClientID%>').click();
            }
        }
           document.attachEvent("onkeydown", onKeySignin);

    if it not works then you mention image button as default



    i hopes it helps you

    Monday, May 25, 2009 2:08 AM
  • User-1171043462 posted

    I think you should read here for all the available options

    http://www.beansoftware.com/asp.net-tutorials/accept-enter-key.aspx

    Monday, May 25, 2009 2:19 AM
  • User-1034726716 posted

    if i type some thing in textbox. and press enter button means particular imagebutton should be fired.
    but some other button only fired. i need imagebuton should be fired in pressing enter button after typing text in textbox

     

    Based on my understanding you want to execute the Button Click event when hitting the Enter key in the TextBox control.. If so then you can refer the following snippet below for your reference:

    ASPX Mark Up and JavaScript function

     
    <head>
    <title>Untitled Page</title>
    </style>
    <script type="text/javascript" language="javascript">

    function controlEnter (obj, event)
    {
    var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
    if (keyCode == 13)
    {
    document.getElementById(obj).click();
    return false;
    }
    else {
    return true;
    }
    }
    </script>
    </head>
    <body>
    <form id="form1" runat="server">

    <asp:TextBox ID="TextBox1" runat="server" ></asp:TextBox>
    <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" />

    </form>
    </body>
     

    RELEVANT CODES:

     
    protected void Page_Load(object sender, EventArgs e)
    {
    TextBox1.Attributes.Add("onkeypress", "return controlEnter('" + Button1.ClientID + "', event)");
    }

    protected void Button1_Click(object sender, EventArgs e)
    {
    Response.Write("Button was Clicked!");
    }

     

    You may also see:

    Forcing Button Click event to fire up when pressing ENTER Key on TextBox

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, May 25, 2009 4:07 AM