Save records by hitting a enter key

Posted on 2006-05-15
Last Modified: 2008-03-17
the "Enter" key.
I have textboxes( item template)  inside of a gridview  and a form view


The use can enter a number inside of the textbox and click save all button to be able to save the records that they just entered.

I was using below code to be able to achive the goal.
Here is the code

 function doFocus(key)
    if(key == 13) document.getElementById('Button2').focus();
 protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        ((TextBox)e.Row.Cells[11].FindControl("TextBox2")).Attributes.Add("onkeydown", "doFocus(window.event.keyCode);");

the functionally of this coce is when the user press the enter key in the textbox then set the focus to the save button... it's like the user do click on the button.

but I am getting an error says: ArgumentOutofRangeException was unhandled by user code. Specified argument ws out of the range of valid values" I made sure that Textbox2 is Cells[11]...

wha I am doing wrong here??
Question by:jung1975
    1 Comment
    LVL 27

    Accepted Solution

    try this in your page_load
    Textbox2.Attributes.Add("onkeydown", "doFocus(window.event.keyCode);");
    if this doesnt work, use findcontrol and attach the client script event


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
    User art_snob ( encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
    Need more eyes on your posted question? Go ahead and follow the quick steps in this video to learn how to Request Attention to your question. *Log into your Experts Exchange account *Find the question you want to Request Attention for *Go to the e…
    how to add IIS SMTP to handle application/Scanner relays into office 365.

    794 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now