Click here to Skip to main content
15,112,304 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have create a html string in json response which create a textbox and i have attached onkeypress function with it but my problem my onkeypress enter function called it will insert so many times in database .what should i do to remove this conflict for multiple insert.
Posted
Comments
Sushil Mate 2-Nov-12 2:21am
   
sharad, what you asking is ambiguous. Whats the hurry to put everything in one statement? use proper punctuation mark. you need to clarify your question with small small statement so we can understand :)
Nathan Stiles 2-Nov-12 2:30am
   
There are probably 20 different ways to solve this issue. You need to get creative. Decide when the data should be inserted, and only let the insert happen at that point. If the data is inserted into the DB, show the user something, change the page, show an lol cat, anything, just make it happen!
sharad_sharma82 2-Nov-12 4:14am
   
but i am working in MVC and using json for key response below is my code so please look at this:
Here is my Html code:

htmlUrls += '<textarea id="txt' + i + '' + response[i].UrlID + '" onkeyup="Trigger('+i+',' + response[i].UrlID + ','+userid+')" onfocus="if(this.value==' + delimiter + 'Write a comment....' + delimiter + ')this.value=' + delimiter + '' + delimiter + ';" onblur="if(this.value==' + delimiter + '' + delimiter + ')this.value=' + delimiter + 'Write a comment....' + delimiter + ';" class="textbox" rows="" cols="" >Write a comment....</textarea>';


Here is my JS function :
<pre lang="cs">function Trigger(counter, urlid, userid) {

var xTriggered = 0;
$('#txt' + counter + '').keyup(function (event) {
xTriggered++;
var msg = 'Handler for .keyup() called ' + xTriggered + ' time(s).';
}).keydown(function (event) {
if (event.which == 13) {
testcommnt(counter, urlid, userid); event.preventDefault();
}
});
// var firsttime = true;
}</pre>


but when i press enter its insert the detail multiple times i dont kw why

1 solution

sorry guys above solution deleted by me,
please refer below one:
hello,

use below code:

private void textBox1_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
// Enter (return) was pressed.
// ... Call a custom method when user presses this key.
AcceptMethod();
}
}

private void AcceptMethod()
{
//here you can write your action for insert data in database;
}

hope this will help you,
happy coding..
   
Comments
sharad_sharma82 2-Nov-12 4:14am
   
but i am working in MVC and using json for key response below is my code so please look at this:
Here is my Html code:

htmlUrls += '<textarea id="txt' + i + '' + response[i].UrlID + '" onkeyup="Trigger('+i+',' + response[i].UrlID + ','+userid+')" onfocus="if(this.value==' + delimiter + 'Write a comment....' + delimiter + ')this.value=' + delimiter + '' + delimiter + ';" onblur="if(this.value==' + delimiter + '' + delimiter + ')this.value=' + delimiter + 'Write a comment....' + delimiter + ';" class="textbox" rows="" cols="" >Write a comment....</textarea>';


Here is my JS function :
<pre lang="cs">function Trigger(counter, urlid, userid) {

var xTriggered = 0;
$('#txt' + counter + '').keyup(function (event) {
xTriggered++;
var msg = 'Handler for .keyup() called ' + xTriggered + ' time(s).';
}).keydown(function (event) {
if (event.which == 13) {
testcommnt(counter, urlid, userid); event.preventDefault();
}
});
// var firsttime = true;
}</pre>


but when i press enter its insert the detail multiple times i dont kw why

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