سؤال

I'm calling a javascript function on OnClientClick of my button control to encode a textbox value that is for an email body text. That JS function calls encodeURI() to encode the text value of textbox.

Markup:

<asp:Button ID = "btnSend" runat = "server" Text= "Send" OnClientClick = "return encodeBody()"/>

JS function:

function encodeBody() {
    document.getElementById(txtBodyID).value =         encodeURI(document.getElementById(txtBodyID).value);
}

The problem is when it posts back the text in the textbox displays the encoded text for a second then it send the email. That's one issue. The other problem is if an error happens users will see the encoded test instead of the original text they entered.

هل كانت مفيدة؟

المحلول

Since you are setting the value of that input field as encoded url, thats why it is visible to users.

To avoid it use hidden input field and set it value to encodedURI

function encodeBody() {
    document.getElementById(hiddenfield).value = encodeURI(document.getElementById(txtBodyID).value);
}
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top