Showing posts with label Sandeep Prajapati. Show all posts
Showing posts with label Sandeep Prajapati. Show all posts

Wednesday, August 21, 2013

Custom Message box and Confirm window all in one

Hello,
I have created a custom message box and confirm window which can be used in all programming languages and all platforms.
syntex :
AlertCust([Control], {Message Title}, [Message Text], {IconType}, {PromptType}, [OnOk], [OnCancel]);



Description :

  • [Control] : Optional, Pass the control which raises the prompt. in Confirm or Alert window when click ‘OK’ button is clicked, the default server event will be executed, if value is passed. if null, clicking on ‘OK’ the prompt window will be closed, no further action.
  • {Message Title} : Required, Message Title. Title will appear in bold font.
  • [Message Text] : Optional, Message text in second line, in normal fonts.
  • {IconType} : Required, Enum values. pass icon type to display icon specific to message. options Error, Warning, Information
  • {PromptType} : Required,  This property helps to decide what kind of prompt we need. e.g. Validation, MessageBox(OkOnly), OKCancel, YesNo.
  • [OnOk] : Optional, To provided custom callback method, set javascript method name, will be executed when clicked ‘OK’.
  • [OnCancel] : Optional, To provided custom callback method, set javascript method name, will be executed when clicked ‘Cancel’.





Message




anyone can download code from Here

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, October 16, 2012

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



Saturday, August 4, 2012

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

str
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 this Helps

All the best.