Posts

Showing posts from 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 elem...

Disable Server Validation Control from ClientSide/ Javascript - ValidatorEnable

Hello Friends, Recently I required to disable server validation control (RequiredFieldValidator, CompareValidator, CustomValidator, RangeValidator, RagularExpressionValidator, etc) from clientside/ Javascript. There are few patches to accomplish the  requirement by I liked an approach which is perfect for ClientSide handling. ValidatorEnable is a javascript mathod lying at asp.net framework javascriptscript ValidatorEnable(document.getElementById(myVal), Status); Thanks

DateTime.ParseExact - culturewise Date Comparision

Hello.. Whenever dealing with cultures, DateTime format is always a headache to handle. to the date format  in Textbox sometimes does not meet the format of culture. in that case DateTime.ParseExact is good option to handle. convert the date into current culture format from display culture format using public static DateTime ParseExact( string str, string Dateformat, IFormatProvider provider) Parameters s tr Type: System.String A string that contains a date and time to convert. Dateformat   Type: System.String A format specifier that defines the required format of s . provider   Type: System.IFormatProvider An object that supplies culture-specific format information about s . example DateTime sessionDate = DateTime.ParseExact(txtDate.Text, "M-d-yyyy", provider); here provide is CultureInfo provider = CultureInfo.InvariantCulture; this will get txtDate.Text (Date) into culture wise date format to compare with database formatted datetime. Hope thi...

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....

Improve Performance by using OUTPUT in Insert Or Update Statement in single query

Image
Hello friends, recently I needed to fire a single SQL statement for Insert and Update and using the single statement I also needed to return the result of all Inserted/Updated Records details.. after searching a lot ... I came to know a very interesting way to perform both statement in single Query. Generally for the scenario I got lots of suggestions to use Stored Procedure, but which was difficult for my scenario. so I must get solution for it. ok ok... let's come to point. let's we have created a sample Table using the query Create Table Table_1(Id Int Identity,Name nvarchar(100)) to insert records and get its generated Id basically we perform like this Insert into Table_1(Name) Select 'Sandeep' Select @@IDENTITY and same way for update here the Updated value comes from other process which is not available Directly [My case is only For Insert. but the concept we can use in Update also] Declare @NewValue nvarchar(100)='Sandeep Prajapat...

Sample for WCF using json

Here is a sample for start WCF using json in aspx page <script type="text/javascript"> function ajaxService2() { serviceUrl = "http://localhost/WCFS/Service1.svc/GetData"; var time = new Object(); time.value = "1"; $.ajax({ type: "POST", url: serviceUrl, data: JSON.stringify(time), contentType: "application/json; charset=utf-8", dataType: "json", success: function (transport) { var string = transport; $("#<%= Text2.ClientID %>").val(string); }, error: function (ex) { alert("error" + ex.responseText); } }); } function ajaxService1() { serviceUrl = "http://localhost/WCFS/Service1.svc/GetAllPr...