Quantcast
Viewing latest article 1
Browse Latest Browse All 3

Answer by Lambda for asp.net textarea line feed and preventing postback on return key

Found a solution: Keep:

body onkeydown="return (event.keyCode!=13)"

this will disable any post back using Return Key, Then add to any multi line textbox the following attribute:

TextBox1.Attributes.Add("onkeyup", "EnterEvent(event,this)");

with the following javascript:

// add Line feed in text area.
function EnterEvent(e,ctl) {
    var keycode = (e.keyCode ? e.keyCode : e.which);
    if (keycode == 13) {

    var st1 = $(ctl).textrange('get', 'start');
    var l = ctl.value.length;
    if (st1 < l) {
        $(ctl).textrange('replace', '\n');
        $(ctl).textrange('set', st1 + 1, 0);
    }
    else {
        ctl.value = ctl.value + '\n';
    }
    }

}

this "manually" insert LF on return key up event.


Viewing latest article 1
Browse Latest Browse All 3

Trending Articles