Showing posts with label Error Handling. Show all posts
Showing posts with label Error Handling. Show all posts

Thursday, November 1, 2012

JavaScriptStringEncode : Javascript Compitable encoding

Hello,

Recently I was facing very interesting issue. and the solution for the issue was introduced in the new updates in asp.net framework 4.0.

Generally when we try to render HTML content on page clientside/ by javascript, it gives error of Potential dangerous content error.

http://msdn.microsoft.com/en-us/library/ms972967.aspx

There are lot's solutions but have to compromise security of page.
by setting

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="default.aspx.cs"
    Inherits="_default" ValidateRequest="false"%>


 But now we have perfect solution which is introduced in .net framework 4.0

HttpUtility.JavaScriptStringEncode Method


URL encoding makes sure that all browsers correctly encodes text in URL strings. Few Characters such as a question mark (?), ampersand (&), slash (/), and spaces might be truncated or corrupted by some browsers. Therefore, these characters must be encoded in a elements or in query strings where the strings can be re-sent by a browser in a request string.

refer following  MSDN link
http://msdn.microsoft.com/en-us/library/system.web.httputility.javascriptstringencode%28v=vs.100%29.aspx

http://msdn.microsoft.com/en-us/library/dd991914%28v=vs.100%29.aspx

Hope this helps

Tuesday, February 14, 2012

Handle Devide By Zero Error

Hi ..
set Arithaboth and Ansi_Warnings as OFF to handle devide by Zero or any kind of arithmatic errors

SET ARITHABORT OFF
SET ANSI_WARNINGS OFF
Declare @Denominator int =0
Declare @Numerator int =5
SELECT isnull(@Numerator / @Denominator,0) as Result


happy coding....

Thursday, May 26, 2011

Track Error in Javascript Page


Hi
Many times we have faced problems to find what is javascript errors and exactly where??
To track javascript error, It is a good practice to write code in Try..Catch
but sometimes some small syntax error are not allowing to execute the whole js file.
so to track such error during development, we can track by this sample code
  <script type="text/javascript">
        onerror = CallOnError;
        function CallOnError(msg, url, line) {
            var strErrMessage = "";
            strErrMessage += "Message: " + msg + "\n";
            strErrMessage += "Page: " + url + "\n";
            strErrMessage += "Line Number: " + line + "\n\n";
            alert(strErrMessage);
            return true;
        }
    </script>
  

Here is a sample error

try to put on your page

  <script type="text/javascript">
            alert('This is First Test Page);
    </script>

Enjoy Coding