Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Save the recordinside of a textbox by hitting "Enter key" in gridview

Posted on 2006-04-17
4
Medium Priority
?
291 Views
Last Modified: 2012-08-13
just hitting the "Enter" key.
I have textboxes( item template)  inside of a gridview  and a form view

((TextBox)row.Cells[11].FindControl("TextBox2")).Text;

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

Is there anyway the user can just hit the "Enter" key to be able to save the record that they just entered? the user want to be able to save the record by just hitting the "enter" key.. I have no idea how I am going to so this..

I am using asp.net 2.0 c#..
0
Comment
Question by:jung1975
  • 2
  • 2
4 Comments
 
LVL 18

Expert Comment

by:Elvio Lujan
ID: 16471898
<script>
function doFocus(key)
{
    if(key == 13) document.getElementById('theIdOfTheButton').focus();
}
</script>

and in the rowdatabound

((TextBox)e.Row.Cells[11].FindControl("TextBox2")).Attributes.Add("onkeydown", "doFocus(window.event.keyCode);");
0
 

Author Comment

by:jung1975
ID: 16471990
Thanks, but I don;t understand your code:   if(key == 13)??

and Is this code "((TextBox)e.Row.Cells[11].FindControl("TextBox2")).Attributes.Add("onkeydown", "doFocus(window.event.keyCode);");"  will let the user save the record that they just entered inside of textbox in gridview?

0
 
LVL 18

Accepted Solution

by:
Elvio Lujan earned 2000 total points
ID: 16472018
the functionally of the comment posted 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
0
 

Author Comment

by:jung1975
ID: 16472089
Thanks, 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]...

I am not sure what I am doing wrong?


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);");
    }
}
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses
Course of the Month21 days, 5 hours left to enroll

810 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