简体   繁体   English

使用encodeURI()时,在回发之前显示已编码的文本

[英]Encoded text displays before postback when using encodeURI()

I'm calling a javascript function on OnClientClick of my button control to encode a textbox value that is for an email body text. 我正在按钮控件的OnClientClick上调用javascript函数,以对用于电子邮件正文的文本框值进行编码。 That JS function calls encodeURI() to encode the text value of textbox. 该JS函数调用encodeURI()来编码文本框的文本值。

Markup: 标记:

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

JS function: JS功能:

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. 由于您将输入字段的值设置为编码的url,因此这对用户可见。

To avoid it use hidden input field and set it value to encodedURI 为了避免这种情况,请使用隐藏的输入字段并将其值设置为encodeURI

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM