Encoded value is displaying on textbox :- encodeURIComponent()

1.2k views Asked by At

I'm calling a javascript function on OnClientClick of my button control to encode a textbox value .
That JS function calls encodeURIComponent() to encode the text value of textbox.

My Javascript function is

function Validate() {
    var d = document.getElementById('<%=NoteText.ClientID %>');
    var Hdn = document.getElementById('HdnProcessing');
    if (d.value == '') {
        alert(document.getElementById('<%=NotesMessage.ClientID %>').value);
        d.focus();
        return false;
    }
    if (Hdn.value == "Processing") {
        return false;
    } else {
        Hdn.value = "Processing";
        var headObj = document.getElementById('<%=NoteHeading.ClientID %>');
        headObj.value = encodeURIComponent(headObj.value);
        d.value = encodeURIComponent(d.value);
        return true;
    }
}

Here my inputs are textboxes ie NoteText and NoteHeading.

If anyone is reading this I was wondering is there anyway to pass the encoded text to the server without the user seeing the encoded text updating in the textbox. Currently when the user clicks the SAVE button they see the text change to the encoded text for a split second before the page refreshes. I was just curious if I could prevent the user from seeing that.

1

There are 1 answers

0
jeffdill2 On

I recently provided an answer to a very similar question that should help you out:

JavaScript encode field without spoiling the display