Asp. NET Popup Display Ex.message exception information there is a newline and carriage return processing method.

Source: Internet
Author: User

1. Put ex. The message is replaced with an arbitrary string, which verifies that the dialog box can be displayed in the Catch statement block using the Response.Write method. The results show success, stating that the problem is in ex. The message.

2. In the program below the breakpoint, you can see ex. The contents of the message are as follows:

Focus is the red circle up the part, there is a carriage return + line symbol, it is estimated that he made the ghost, apart, directly remove it, the code is as follows:

Try

{//... .

} catch (Exception ex)

{

Response.Write ("<script language= ' javascript ' >alert (\" "+ Ex.)  Message.replace ("\\r\\n", " ") + "\");</script> ");

}

But that still doesn't work! It's still not showing!

3. After a near-collapse of the exploration, and finally found the problem, indeed is \ r \ NAND, but I replace the wrong way. The next breakpoint to see is \ r \ n (), the \ is already an escape character, used to escape R and N, the true meaning of the expression is carriage return + newline. And I write \\r\\n, is in the former \ escaped after a \,r and N is treated as a normal character, the true meaning of the expression is \ r \ n. That's certainly not the way to replace it! So the correct wording is as follows:


Try

{ //... .

}

catch (Exception ex)

{

Response.Write ("<script language= ' javascript ' >alert (\" "+ Ex.)  Message.replace ("\ r \ n", " ") + "\");</script> ");

}

This will be a perfect display!

In fact, there are a lot of such problems on the Internet, the answer is not because they and I made the same mistake, the escape character write more, later encountered a similar problem directly to remove the carriage return + line (such as display a read text, inside contains carriage return line)! Hope this small experience can help everyone!

Reprint: http://blog.csdn.net/yangyuankp/article/details/7630115

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.