Monday, June 8, 2009

Shortcut Keys of Edit Menu in VS 2008

Check the follwoing Link
http://www.dotnetspider.com/resources/28921-Shortcut-Keys-Edit-Menu-VS.aspx

Organize Usings

Once we have created our class. In that class we use the using statment at the top of the class.To include namespaces in our class. But sometimes we realize after compeleting the code of that calss we have used some extra namespaces which are of no use in th class to remove all those unused using statment. we can use InteliSense in the edit menu. in the submenu of InteliSense we will find the option organize usings. and in its sub menu we hve the options to remove unused usings to sort usings and to remove and sort usings.


Thanks and Regards
Meetu Choudhary

Friday, June 5, 2009

Format document

To format any document (.cs,XML,aspx,HTML etc) in visual studio 2008
use the following key combinations:
To format whole document : ctrl +k ,(followed by) ctrl + d
To format the selection : ctrl +k, (followed by) ctrl +f




Thanks and Regards
Meetu Choudhary

Wednesday, June 3, 2009

Accessing the properties of a digital signature

Accessing the properties of a digital signature



Now once we have selected the certificate. We need to access the properties of the certificate. Here is a small piece of code to access all the properties which may be helpful to us for any context.

before accessing these properties we have to set the certificate object. for that you can get the code from any of the two previous articles.
1. Article link , Mirror link
2. Article link , Mirror link


Now once we have the certificate (X509Certificate2 x509_2;)
we can o with the following code

[code]

///



/// Set All the Properties of the Certificate

///


public Boolean SetProperties()

{

if (x509_2 != null)

{

RSACryptoServiceProvider rsa = (RSACryptoServiceProvider)x509_2.PublicKey.Key;

_PublicKey_Key =_PublicKeyXML = rsa.ToXmlString(false);

//_PrivateKeyXML = rsa.ToXmlString(true );

_PrivateKeyXML=_Private_Key = x509_2.PrivateKey.ToXmlString(false);

_PKeyExchangeAlgorithm = x509_2.PrivateKey.KeyExchangeAlgorithm;

_PublicKey = x509_2.GetPublicKeyString();

//_PublicKey_Key = Convert.ToString(x509_2.PublicKey.Key);

_SerialNumber = x509_2.GetPublicKeyString();

_Thumbprint = x509_2.Thumbprint;

_RawCertDataString = x509_2.GetRawCertDataString();

_FriendlyName = x509_2.FriendlyName;

_HashString = x509_2.GetCertHashString();

_EffectiveDate = x509_2.GetEffectiveDateString();

_ExpirationDate = x509_2.GetExpirationDateString();

_Format = x509_2.GetFormat();

_IssuerName = x509_2.GetIssuerName();

_KeyAlgorithm = x509_2.GetKeyAlgorithm();

_KeyAlgorithmParameters = x509_2.GetKeyAlgorithmParametersString();

_CertName = x509_2.GetName();

_CertSubject = x509_2.Subject;

_CertVersion = x509_2.Version;

_SignatureAlgorithm_Value = x509_2.SignatureAlgorithm.Value;

_SignatureAlgorithm_ToString = x509_2.SignatureAlgorithm.ToString();

_SignatureAlgorithm_FriendlyName = x509_2.SignatureAlgorithm.FriendlyName;

return true;

}

else { return false; }

}

[/code]




Thanks and Regards
Meetu Choudhary

Open Certificate Stores Including Certificates in Token

Open Certificate Stores Including Certificates in Token



In My Previous article Mirror Link I have shown how to open a certificate store (Machine certificate store which is displayed in the Internet Explorer.) but the drawback of that code was it can't open the certificates stored in the token. so here is another method which will overcome the drawback stated above. It will open the certificates of the machine store as well as of the tokens.

[code]
///

/// Opens the Certificate Store of IE including the Certificates in Token

///


/// The variable passed to store the reason if function returns false

/// True if a certificate is selected and false if no certificate is selected

public Boolean OpenStoreToken(ref string popupScript)

{

x509_2 = null;

//Create and Initilaize a variable of x509Store providing the store name and the store location

X509Store st = new X509Store(StoreName.My, StoreLocation.CurrentUser);

//Create X509Certificate2Collection

X509Certificate2Collection col = new X509Certificate2Collection();

//Create X509Certificate2Collection

X509Certificate2Collection sel = new X509Certificate2Collection();

//Create X509Certificate2Enumerator

X509Certificate2Enumerator en;// =new X509Certificate2Enumerator();

//Open the Store for readonly purpose

st.Open(OpenFlags.ReadOnly);

//set the col i.e. X509Certificate2Collection to the collection of the certificates stored in the IE and the Token

col = st.Certificates;

//set the sel i.e. X509Certificate2Collection which actuly displays a dialog box for selecting an X.509 certificate from a certificate collection.

sel = X509Certificate2UI.SelectFromCollection(col, "Certificates", "Select one to sign", X509SelectionFlag.SingleSelection);

if (sel.Count > 0)

{

en = sel.GetEnumerator();

en.MoveNext();

x509_2 = en.Current;

}

st.Close();

if (x509_2 == null)

{

popupScript = "You didn't select a certificate!!!";

return false;

}

else

{

return true;

}

}



[/code]



Thanks and Regards
Meetu Choudhary

Thursday, May 28, 2009

Open Certificate Stores

Open Certificate Stores



I am working on Digital Signatures with ASP.Net. Once in a life time for a programmer we get a chance to work for security or with security and even myself is not an exception . I have to work with digital signatures to achieve security and I searched a lot in internet to achieve what i need and I am still in the process to learn more but in this journey I have found many things but most of them were related to java and applets as I was form .net domain I had to work on it. So here I am Starting the discussion with the first obstacle I met, it is to open a certificate store as of Internet Explorer... I am calling it first as I need not to generate the digital signature as I have them which were already issued by the authorized CA. still if you want to have a look then you can go through the link where i have explained how to create a certificate.. or the mirror link...

Proceeding further... I have encountered two ways to open a certificate store discussing them here..


Method One:



Certfun is a class which i found on the Internet which i don't remember where exactly but i have modified that class as i found that code in vb and i need that in C# so i will paste the code at the end

Limitation:-- This will not open the certificate in the token.

[code]
///

/// Opens the Certificate Store of IE Excluding the Certificates in Token

///


/// The variable passed to store the reason if function returns false

/// True if a certificate is selected and false if no certificate is selected

public Boolean OpenStoreIE(ref string popupScript)

{

x509_2 = null;

//declare a pointer and initilize it with Zero This pointer will hold the value returened by opening the Store

IntPtr hCertStore = IntPtr.Zero;

//declare a pointer and initilize it with Zero This pointer will hold the value returened by selecting the certificate from the store

IntPtr pCertContext = IntPtr.Zero;

//Declare a string and Intilaize it with the store name to open by default it is 'My' Stroe from where we store or install the certificates

string kk = "MY";

//Declaring a StringBuilder Object to hold the NameString of the certificate

StringBuilder NS = new StringBuilder(128);

//To hold the size

int provinfosize = 0;

//Opens the Store and returns a pointer handler of the Store.

hCertStore = CertFun.CertOpenSystemStore(IntPtr.Zero, kk);

//Will returns the pointer handler of the selected certificate

pCertContext = CertFun.CryptUIDlgSelectCertificateFromStore(hCertStore, IntPtr.Zero, "Personal Store", "Please select a PKC12 (.pfx) Certificate and press ok", cf.CRYPTUI_SELECT_LOCATION_COLUMN, 0, IntPtr.Zero);

//Testing if the pointer handler is equal to zero then informing the user that no certificate is selected and exiting the function

if (pCertContext.Equals(IntPtr.Zero))

{

popupScript = "You didn't select a certificate!!!";

//ScriptManager.RegisterClientScriptBlock(Page, this.GetType(), "nocert", popupScript, false);

return false;

}

//check certificate is PKCS12

if (!CertFun.CertGetCertificateContextProperty(pCertContext, cf.CERT_KEY_PROV_INFO_PROP_ID, IntPtr.Zero, ref provinfosize))

{

//Check the pointer handler if it is not eqal to zero then

if (!(pCertContext.Equals(IntPtr.Zero)))

{

//free the pointer handler as the certificate is not PKCS12

CertFun.CertFreeCertificateContext(pCertContext);

}

//Display a message and exit from the function

popupScript = "Selected certificate is not PKCS12. Please select a PKCS12 certificate!!!";

//ScriptManager.RegisterClientScriptBlock(Page, this.GetType(), "invalidcert", popupScript, false);

return false;



}

else

{

// yes pkcs12

//need not to do anything here

}

//Get Name String for the Certificate into your stringbuilder created above

if ((CertFun.CertGetNameString(pCertContext, cf.CERT_NAME_SIMPLE_DISPLAY_TYPE, 0, IntPtr.Zero, NS, 128)))

{

}

else

{

// Can Display the message here that certificate name failed

//in my case no requirement to display this message

}

//Now store the user selected certificate into the global static variable for later use

x509_2 = new X509Certificate2(pCertContext);

return true;

}
[/code]


CertFun



[code]
using

System;

using

System.Runtime.InteropServices;

using

System.Security.Cryptography;

using

System.Text;

namespace

Secure_Login

{

///

/// Summary description for CertFun

/// class which will handle and implemet the delegates

///


public class CertFun

{

[StructLayout(LayoutKind.Sequential)]

public struct CRYPTUI_CERT_MGR_STRUCT

{

public int dwSize;

public IntPtr hwndParent;

public int dwFlags;

public string pwszTitle;

public IntPtr pszInitUsageOID;

}

[StructLayout(LayoutKind.Sequential)]

public struct CRYPT_KEY_PROV_INFO

{

[MarshalAs(UnmanagedType.LPWStr)]

public string ContainerName;

[MarshalAs(UnmanagedType.LPWStr)]

public string ProvName;

public int ProvType;

public int Flags;

public int ProvParam;

public IntPtr rgProvParam;

public int KeySpec;

}

[DllImport("cryptui.dll", SetLastError = true)]

public static extern IntPtr CryptUIDlgSelectCertificateFromStore(IntPtr hCertStore, IntPtr hwnd, [MarshalAs(UnmanagedType.LPWStr)]

string

pwszTitle, [MarshalAs(UnmanagedType.LPWStr)]

string

pwszDisplayString, int dwDontUseColumn, int dwFlags, IntPtr pvReserved);

[DllImport("crypt32.dll", SetLastError = true)]

public static extern IntPtr CertEnumCertificatesInStore(IntPtr hCertStore, IntPtr pPrevCertContext);

[DllImport("crypt32.dll", SetLastError = true)]

public static extern bool CertGetNameString(IntPtr pCertContext, int dwType, int dwFlags, IntPtr pvTypePara, StringBuilder pszNameString, Int32 cchNameString);

[DllImport("crypt32.dll", SetLastError = true)]

public static extern bool CertGetCertificateContextProperty(IntPtr pCertContext, int dwPropId, IntPtr pvData, ref int pcbData);

[DllImport("crypt32.dll", CharSet = CharSet.Auto, SetLastError = true)]

public static extern IntPtr CertOpenSystemStore(IntPtr hCryptProv, string storename);

[DllImport("crypt32.dll", SetLastError = true)]

public static extern bool CertFreeCertificateContext(IntPtr hCertStore);

[DllImport("crypt32.dll", SetLastError = true)]

public static extern bool CertCloseStore(IntPtr hCertStore, int dwFlags);

[DllImport("cryptui.dll", SetLastError = true)]

public static extern bool CryptUIDlgCertMgr(ref CRYPTUI_CERT_MGR_STRUCT pCryptUICertMgr);

[DllImport("crypt32.dll")]

public static extern bool CryptDecodeObject(int CertEncodingType, int lpszStructType, byte[] pbEncoded, int cbEncoded, int flags, [In(), Out()]

byte

[] pvStructInfo, ref int cbStructInfo);



[DllImport("crypt32.dll", SetLastError = true)]

public static extern IntPtr CertFindCertificateInStore(IntPtr hCertStore, int dwCertEncodingType, int dwFindFlags, int dwFindType, [In(), MarshalAs(UnmanagedType.LPWStr)]

string

pszFindString, IntPtr pPrevCertContext);

[StructLayout(LayoutKind.Sequential)]

public struct PUBKEYBLOBHEADERS

{

////BLOBHEADER

public byte bType;

// //BLOBHEADER

public byte bVersion;

////BLOBHEADER

public short reserved;

////BLOBHEADER

public Int32 aiKeyAlg;

// //RSAPUBKEY

public int magic;

//; '//RSAPUBKEY

public int bitlen;

//; //RSAPUBKEY

public int pubexp;

}

public int CERT_NAME_SIMPLE_DISPLAY_TYPE = 0x4;

public int CRYPTUI_SELECT_LOCATION_COLUMN = 0x10;

public int CERT_KEY_PROV_INFO_PROP_ID = 0x2;

static public int X509_ASN_ENCODING = 0x1;

static public int PKCS_7_ASN_ENCODING = 0x10000;

public int RSA_CSP_PUBLICKEYBLOB = 19;

static public int ENCODING_TYPE = PKCS_7_ASN_ENCODING | X509_ASN_ENCODING;

public int CERT_FIND_SUBJECT_STR = 0x80007;

public byte[] pubblob;

public string PKC12CertSelectedName = "";

public byte[] EncKey;

public byte[] EncIv;

public byte[] EncData;

//creates new instance of Rinjndael

public RijndaelManaged Rin = new RijndaelManaged();

public byte[] SignedData;

public string CertForEnc = "";

public string CertForSig = "";

}

}

[/code]

I will Cover the next method in my next resource which will overcome the limitation of the method one



Thanks and Regards
Meetu Choudhary

Wednesday, May 27, 2009

Few moments with Dotnetspider : DNS-MVM award

In continuation on my award of MVM from dotnetspider.com, DNS published my interview on this award.

In this interview I have shared my views with Raghav on my this achievement.

The tenure of interview is around 60-minutes, I really enjoyed with Raghav.

Here is the link of my interview : http://www.dotnetspider.com/forum/206923-Few-moments-with-Meetu-Choudhary-DotNetSpider-MVM.aspx

Sunday, May 24, 2009

Few moments with Dotnetspider : DNS-MVM award

In continuation on my award of MVM from dotnetspider.com, DNS published my interview on this award.

In this interview I have shared my views with Raghav on my this achievement.

The tenure of interview is around 60-minutes, I really enjoyed with Raghav.

Here is the link of my interview : http://www.dotnetspider.com/forum/206904-Few-moments-with-Gaurav-Arora-DotNetSpider-MVM.aspx

Sunday, May 3, 2009

A great eve in Hyderabad - Microsoft TechEd2009

Lets cheers, its a good news for all Microsoft lovers.
Microsoft TechEd2009 will be conducting in Hyderabad from May13 to May15.

Main attention of the eve is Steven A. Ballmer,CEO Microsoft. This is the greatest and biggest eve in India and expecting to see a huge crowd from developer community.

To grab more details please visit : Microsoft TechEd2009.

Thursday, April 30, 2009

Using enum Search Database

Using enum Search Database

This example demonstrates the use of enum.
How this enum is used to set the way to fecth data from the database

Declaring enum



/// this enum will define in which way the search should be made
/// all stats that the parameter should exactly match
/// start states that the vlaue passed should be serched for any value starting with
/// End states that the vlaue passed should be serched for any value ending with
/// Middle states that the vlaue passed should be serched for any value which conatins these charates any where
///

public enum SearchDirection
{
All=0,
Start=1,
End=2,
Middle=3
}


Declaring and Defining the function



///
/// Checks the Field Value whether exist in database or not
///

/// Value to check for
/// Value to check in which field
/// Value to Check in which Table
/// Specifies the search direction
///
public Int32 CheckFieldValue(String fldValue, String fldName,String TblName,SearchDirection SearchDir)
{

String strquery = "";
String str=Enum.GetName(typeof(SearchDirection),SearchDir);
if(((Int32)Enum.Parse(typeof(SearchDirection),str))==0)
{
strquery = "select * from " + TblName + " where " + fldName + " ='" + fldValue + "'";
}
else if (((Int32)Enum.Parse(typeof(SearchDirection), str)) == 1)
{
strquery = "select * from " + TblName + " where " + fldName + " like'" + fldValue + "%'";
}
else if (((Int32)Enum.Parse(typeof(SearchDirection), str)) == 2)
{
strquery = "select * from " + TblName + " where " + fldName + " like'%" + fldValue + "'";
}
else if (((Int32)Enum.Parse(typeof(SearchDirection), str)) == 3)
{
strquery = "select * from " + TblName + " where " + fldName + " like'%" + fldValue + "%'";
}

SqlConnection DBConnection = new SqlConnection();
SqlCommand DBCommand = new SqlCommand();
if (DBConnection.State == ConnectionState.Closed)
{
DBConnection.ConnectionString = "yourConnectionString";
DBConnection.Open();
}
DBCommand.Connection = DBConnection;
DBCommand.CommandText = strquery;
Int32 i=DBCommand.ExecuteNonQuery();
DBConnection.Close();
return i;

}



++
Thanks and Regards
Meetu Choudhary
http://msdotnetmentor.com

Wednesday, April 29, 2009

MVM from DotnetSpider.com

Its a very cool Morning today. I got a call from Gaurav Arora informing me that I got the MVM Award and then foolwed by a mail from Raghav , The webmaster of http//:dotnetspider.com regarding the Most Valuable Member award from Dotnetspider. This is the moment of my dreams come true. Here are the few lines from the mail :

Congratulations from dotnetspider.com! Your contributions to the technology world is recognized by dotnetspider.com, one of the most respected technology community. We are glad to inform you that you are selected as the MOST VALUABLE MEMBER (MVM) for your active participation and contribution to dotnetspider.com. You will be awarded with a certificate of appreciation from us.Visit this page for the list of winners - http://www.dotnetspider.com/credits/Index.aspx
and you can catch the annoucment at
http://www.dotnetspider.com/forum/203217-Winners-MVM-award.aspx

My thanks to DNS family for this award and special thanks to Raghav who showed the faith in me and to Gaurav Arora who have nominated me for this prestigious award.

Sunday, April 26, 2009

How to Scale your entire App and its Elements to your Browsers Size

How to Scale your entire App and its Elements to your Browsers Size



Wow, Today I found the answer of the question "How to Scale your entire App and its Elements to your Browsers Size?" And the answer provided to me is by the silverlight 2.0. I always wonder that how can i scale my application to different browser sizes... and to different screen resolutions I found some PHP sites which were scalable according to the browser size but was unable to handle the same in my ASP.net applications... I have Hear-ed a lot about the silverlight and its applications but never give a thought to it and now finally when my client needs the scalable sites then i have no other option left with me i have to search it and thought to go ahead with silverlight and today only i get all the essentials for the silverlight and started to find the solution and to my wonders i found the solution so simple and easy... Here I would like to share it with you all...

we can achieve it in simple two steps

Step 1:

Add the following line of code to the canvas... in page.xaml....
[code]
< Canvas.RenderTransform >
< ScaleTransform x:Name="CanvasScale" ScaleX="1" ScaleY="1" > < /ScaleTransform >
< /Canvas.RenderTransform >
[/code]

and the example code i took to demonstrate it is
[code]
<
UserControl xmlns:inputToolkit="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Input.Toolkit" x:Class="SilverlightApplication1.Page"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Width="400" Height="300" >
< Grid x:Name="LayoutRoot" Background="White" >
< Canvas Height="150" Width="400" Background="Bisque" VerticalAlignment="Center" >
< Canvas.RenderTransform >
< ScaleTransform x:Name="CanvasScale" ScaleX="1" ScaleY="1" > < /ScaleTransform >
< /Canvas.RenderTransform >
< Button x:Name="myButton" Canvas.Top="50"
Canvas.Left="75" Content="Click Me"
Height="37" Width="118" Click="myButton_Click"
ToolTipService.ToolTip ="Click to change above text"/ >
< Button x:Name="myButton1" Canvas.Top="50"
Canvas.Left="195" Content="Click Me"
Height="37" Width="118"/ >
< /Canvas >
< /Grid >
< /
UserControl >
[/code]


Step 2:

Add the following piece of code in the page.xaml.cs
in page()
[code]
App.Current.Host.Content.Resized += new EventHandler(Content_Resized);
[/code]

and the function
[code]
void
Content_Resized(object sender, EventArgs e)
{
double height = App.Current.Host.Content.ActualHeight;
double width = App.Current.Host.Content.ActualWidth;
CanvasScale.ScaleX = width / _startingWidth;
CanvasScale.ScaleY = height / _startingHeight;
}
[/code]

in my example
[code]
using
System;
using
System.Collections.Generic;
using
System.Linq;
using
System.Net;
using
System.Windows;
using
System.Windows.Controls;
using
System.Windows.Documents;
using
System.Windows.Input;
using
System.Windows.Media;
using
System.Windows.Media.Animation;
using
System.Windows.Shapes;
namespace
SilverlightApplication1
{
public partial class Page : UserControl
{
private int _startingWidth = 800;
private int _startingHeight = 600;
public Page()
{
InitializeComponent();
App.Current.Host.Content.Resized += new EventHandler(Content_Resized);
}
private void myButton_Click(object sender, RoutedEventArgs e)
{
}
void Content_Resized(object sender, EventArgs e)
{
double height = App.Current.Host.Content.ActualHeight;
double width = App.Current.Host.Content.ActualWidth;
CanvasScale.ScaleX = width / _startingWidth;
CanvasScale.ScaleY = height / _startingHeight;
}
}
}
[/code]


Test Yourself....
I am sure you will also enjoy as I did.....



Thanks and Regards
Meetu Choudhary

Tuesday, April 7, 2009

Makecer.exe

makecer.exe



makecer.exe is te tool which omes with the visual studio using this tool we can create self signed certificates.



steps once have to follow to create the self signned document



1. open the visual studio command promt

2. type the foolowing command to check the makecer.exe is installed on your system or not 99.9% it is instaled in your system as it is the tool hich vs provieds you

[code]

makecer

[/code]



3. If the above command works then use the following command to create a certificate.



[code]

makecert -sk "MyContainer" -ss MY -r -n "CN=YourCommonName" mycer.cer

[/code]



this will creates an RSA key-pair and a matching certificate in the CurrentUser "MY" certificate store, and also give the output as a public certificate to the file mycer.cer.



The matching private key is placed in the CryptoAPI keycontainer named "MyContainer"(which contains the encrypted private key for this certificate).

The cert is self-signed (-r) and is exportable with private key (-pe).


You can use that keycontainer name (MyContainer) to instantiate a .NET CSP instance too.





++



Thanks and Regards

Meetu Choudhary

http://msdotnetmentor.com

Isnumeric function in JavaScript

Creating a JavaScrit Functon to check the Numeric Values in a field... Unfortunalltyl which is not there inJavaScript By Default...
the function goes like This

[code]
< SCRIPT language="JavaScript" >
<!--
function chkNumeric(strString)
// strString is the string passed to be checked

// check for valid numeric strings
{
// strvalidchars defines the set of characters which are valid in a numeric field
var strValidChars = "0123456789.-";
// strings
var strChar;
// boolresult is the variable which returns true is string is in correct format or false if it is not a valid numeric string
var boolResult = true;

if (strString.length == 0) return false;
// test strString consists of valid characters listed above
for (i = 0; i < strString.length && boolResult == true; i++)
{
strChar = strString.charAt(i);
if (strValidChars.indexOf(strChar) == -1)
{
boolResult = false;
}
}
return boolResult;
}

// -->
</SCRIPT>
[/code]

Now once a function is ready we can use it as follows to check a field and returns an error
message if the contents are not numeric:

[code]
if (document.formname.fieldname.value.length == 0)
{
alert("Please enter a value.");
}
else if (chkNumeric(document.formname.fieldname.value) == false)
{
alert("Please check - the string conatins non numeric value!");
}

[/code]





++

Thanks and Regards

Meetu Choudhary

(http://msdotnetmentor.com)

Wednesday, March 25, 2009

Silverlight 3- Beta - released

Silverlight 3- Beta - released

MicroSoft Released its Silverlight3 beta in MIX [conference for designers and developers at Las Vegas].

Its available for download at:

1. MicroSOft Silverlight 3 SDK Beta 1
2. MicroSoft Silverlight 3 Tools Beta 1 for Visual Studio 2008 SP1
3. The MicroSoft 3 beta Runtime

Tuesday, March 24, 2009

Creating Calender Using Java Script

Following is the JavaScript Code for the HTML File....the whole file is posted as an attachment please have a look on that for detailed Information...
Script in Head Tag
[code]
function showseldate(obj)
{
if(obj.value!="")
{
seldate.innerHTML="<b>" + parseInt(document.calform.drpmonth.value)+1 + "/" + obj.value + "/" + document.calform.drpyear.value + "</b>";
} }
function changecalendar()
{
var m,y;
m=document.calform.drpmonth.value;
y=document.calform.drpyear.value;
displaycalendar(m,y);
}
function showcurcal()
{
var dt=new Date();
var m,y; m=dt.getMonth(); y=dt.getFullYear();
displaycalendar(m,y);
}
function displaycalendar(m,y)
{
var nod=numofdays(parseInt(m)+1,y);
var wd; var dt=new Date();
var curday=dt.getDate(); dt.setDate(1);
dt.setMonth(m); dt.setFullYear(y); wd=dt.getDay();
clear();
for(var i=1;i<=nod;i++)
{
document.calform.txtday[wd].value=i;
if(i==curday)
{
document.calform.txtday[wd].style.backgroundColor="red";
document.calform.txtday[wd].style.color="white";
}
wd++;
}
}
function clear()
{
for(var i=0;i<42;i++)
{
document.calform.txtday[i].value="";
} }
[/code]
In Body[code]
for(var i=1;i<=6;i++)
{
document.write("tr bgcolor='#FFCC00' >");
for(var j=1;j<=7;j++)
{
document.write("td><div align='center'><input name='txtday' type='text' size='3' onclick='showseldate(this)' readonly></div></td>");
} document.write("</tr>"); }[/code]


--
Thanks and Regards
Meetu Choudhary

Monday, March 23, 2009

Blinking Text Using JavaScript

functions for the script tag in body
[code]
function prog1(objid)
{
var obj;
obj=window.document.getElementById(objid);
obj.style.backgroundColor="red";
obj.style.color="yellow";
}
function prog2(objid)
{
var obj;
obj=document.getElementById(objid);
obj.style.backgroundColor="yellow";
obj.style.color="red";
}
function blinktext()
{
if(p3.style.visibility=="visible")
{
p3.style.visibility="hidden";
}
else
{
p3.style.visibility="visible";
}
window.setTimeout("blinktext()",300);
}
[/code]
call binktext function onload of body tag and
in p tag use the following line
[code]
onmouseover="prog1('p1')" onmouseout="prog2('p1')"
[/code]

for more details please see the attachment
--
Thanks and Regards
Meetu Choudhary

Use a session variable in the class files in c# ASP.Net

To use the value of a session variable in the class files using c# with ASP.Net use the following statement

direct use of Session collection is not allowed in the .cs files so to achieve the purpose we have to follow the whole path i.e

System.Web.HttpContext.Current.Session["varname"].ToString()

Example:
[code]
System.Web.HttpContext.Current.Session["con1"].ToString()
[/code]
++
Thanks and Regards
Meetu Choudhary

ASP page with database handling

ASP page with database handling

Here is an Sample Example Which Handles MYSQL 5.0 DataBase with .Net

[code]
<%
//This page will be refreshed with each access!
Response.Expires=-1
%>


<%
//create connection object
set con=server.createobject("adodb.connection")
//Conection String and open the connection
call con.open("provider=msdasql;driver={Mysql};server=mysqlServerName;uid=username;pwd=password;database=dbnsme;")
//For Select Query Execution
set rs=con.execute("select * from tablename )
//displaying the records in a table format
//loop till rs has records
while not rs.eof
response.write("<tr><td>" & rs.fields(0) & "</td><td>" & rs.fields(1) & "</td></tr>")
rs.movenext
wend
rs.close()
response.write("</table>")


//Update Process


//update query
//a will contain how mny records are modified
con.execute("Upadte Query goes here"),a
response.write(a & " records updated")
//response.write("Done")



//Insert Process


//insert query
con.execute("insert into RegClLog (SrNo,ProdKey,ClDtTm) values('"& request.form("hidSrno") &"','"& request.form("hidResult") &"','"& request.form("hidClDtTym") &"') "),a
response.write(a & " records Inserted")

//close connection
con.Close()
%>

<html>
<head></head>
<body>
<form action="#" method="post">
Any HTML CODE here will run perfectly. to display the page

</form>
</body>
</html>


//Trapping Errors in ASP.
//This will get the last error occurred.
<%
dim objErr
set objErr=Server.GetLastError()
response.write("ASPCode=" & objErr.ASPCode)
response.write("
")
response.write("ASPDescription=" & objErr.ASPDescription)
response.write("
")
response.write("Category=" & objErr.Category)
response.write("
")
response.write("Column=" & objErr.Column)
response.write("
")
response.write("Description=" & objErr.Description)
response.write("
")
response.write("File=" & objErr.File)
response.write("
")
response.write("Line=" & objErr.Line)
response.write("
")
response.write("Number=" & objErr.Number)
response.write("
")
response.write("Source=" & objErr.Source)
%>

[/code]


Thanks and Regards
Meetu Choudhary
Founder: http://www.msdotnetmentor.com

Keycodes at a glance

While working in the real time development environment some times we feel a great need to know the key codes by which a character is represented. as the computer does not understands the graphical representation but using the keycodes and keyascii we can trace the character used by the user so here is the list for your use. keeping in mind the windows operation system.

Key Code

0 
1 
2 
3 
4 
5 
6 
7 
8 * *
9 * *
10 * *
11 
12 
13 * *
14 
15 
16 
17 
18 
19 
20 
21 
22 
23 
24 
25 
26 
27 
28 
29 
30 
31 
32 [space]
33 !
34 "
35 #
36 $
37 %
38 &
39 '
40 (
41 )
42 *
43 +
44 ,
45 -
46 .
47 /
48 0
49 1
50 2
51 3
52 4
53 5
54 6
55 7
56 8
57 9
58 :
59 ;
60 <
61 =
62 >
63 ?
64 @
65 A
66 B
67 C
68 D
69 E
70 F
71 G
72 H
73 I
74 J
75 K
76 L
77 M
78 N
79 O
80 P
81 Q
82 R
83 S
84 T
85 U
86 V
87 W
88 X
89 Y
90 Z
91 [
92 \
93 ]
94 ^
95 _
96 `
97 a
98 b
99 c
100 d
101 e
102 f
103 g
104 h
105 i
106 j
107 k
108 l
109 m
110 n
111 o
112 p
113 q
114 r
115 s
116 t
117 u
118 v
119 w
120 x
121 y
122 z
123 {
124 |
125 }
126 ~
127 
128 €
129 
130 ‚
131 ƒ
132 "
133 …
134 †
135 ‡
136 ˆ
137 ‰
138 Š
139 ‹
140 Œ
141 
142 Ž
143 
144 
145 '
146 '
147 "
148 "
149 o
150 -
151 -
152 ˜
153 ™
154 š
155 ›
156 œ
157 
158 ž
159 Ÿ
160 [space]
161 ¡
162 ¢
163 £
164 ¤
165 ¥
166 ¦
167 §
168 ¨
169 ©
170 ª
171 "
172
173 *
174 ®
175 ¯
176 °
177 ±
178 ²
179 ³
180 ´
181 µ
182
183 ·
184 ¸
185 ¹
186 º
187 "
188 ¼
189 ½
190 ¾
191 ¿
192 À
193 Á
194 Â
195 Ã
196 Ä
197 Å
198 Æ
199 Ç
200 È
201 É
202 Ê
203 Ë
204 Ì
205 Í
206 Î
207 Ï
208 Ð
209 Ñ
210 Ò
211 Ó
212 Ô
213 Õ
214 Ö
215 ×
216 Ø
217 Ù
218 Ú
219 Û
220 Ü
221 Ý
222 Þ
223 ß
224 à
225 á
226 â
227 ã
228 ä
229 å
230 æ
231 ç
232 è
233 é
234 ê
235 ë
236 ì
237 í
238 î
239 ï
240 ð
241 ñ
242 ò
243 ó
244 ô
245 õ
246 ö
247 ÷
248 ø
249 ù
250 ú
251 û
252 ü
253 ý
254 þ
255 ÿ

The Symbol :  represents those characters which are not supported by Microsoft Windows.

The Values 8, 9, 10, and 13 are converted into backspace, tab, linefeed, and carriage return characters, respectively.
They can not be graphically represented but, depending on the application, they can affect the visual display of text.

The values in the table are the Windows default.
where as, values in the ANSI character set above 127 are determined by the code page which is specific to the operating system.

++
Thanks and Regards
Meetu Choudhary
Founder: http://www.msdotnetmentor.com

Saturday, March 14, 2009

JavaScript String Replace All

JavaScript String Replace All

Today When I was working I came across the need to replace all the “’” marks with null or with nothing like “” as the “’” mark produces an error while handling with database I have the StringBuldier Class and could replace all at once but to use that it will be a server side code that means irrespective of anything on textchanged event the page should be postback so I decided to use the JavaScript function replace ()

Now the problem with this JavaScript String Replace function is that it replaces the first occurrence in the string. It takes two simple parameters. The first parameter is the pattern to find and the second parameter is the string to replace the pattern with when found. The JavaScript function does not Replace All...







[code]

str=”http://www.msdotnetheaven.com and http://www.msdotnetheaven.com”;

str = str.replace(/heaven/,”mentor”)



[/code]



The output



str=”http://www.msdotnetmentor.com and http://www.msdotnetheaven.com”;







To make the replace function of the JavaScript to replace all the occurrences of the matched string we have to apply a trick and the trick is, use the g modifier like this:



[code]

str=”http://www.msdotnetheaven.com and http://www.msdotnetheaven.com”;

str = str.replace(/heaven/g,”mentor”)





[/code]







The output



str=”http://www.msdotnetmentor.com and http://www.msdotnetmentor.com”;

Friday, March 13, 2009

Type Text in Upper Case using CSS

Type Text in Upper Case using CSS

While working with web application forms. When we create the forms which can be filled online and then printed to submit we came across the need that the particular textbox such as Name or Father’s Name should be filled in capital letters as most of the conventional forms need this. To accomplish this task we can take help of the CSS property by writing a single line code we can lower our most of the extra work and can concentrate on other parts of the code here is a small example to achieve what I have described above. Here we go:

Type Text in Upper Case using CSS

[code]

< head runat="server" >
< title > Upper Case < /title >
< style type="text/css" >
.test
{
text-transform: uppercase;
}
< /style >
< /head >
< body >
< form id="form1" runat="server" >
< div >

< /div >
< asp:TextBox ID="TextBox1" runat="server" CssClass="test" > < /asp:TextBox >
< /form >
< /body >

[/code]


Thanks and Regards
Meetu Choudhary
founder: http://www.msdotnetmentor.com

No scrollbar on HTML web pages - JavaScript code

No scrollbar on HTML web pages - JavaScript code

In my previous article I described how we can hide a scrollbar from user's view by putting the same color value as the web page.

What I have described in that article is absolutly fine for those web pages whose content fits in the browser display area because Netscape and Mozilla display no scrollbars for such pages and as far as IE is concern the scrollbar can be made transparent or hidden as it recognizes the CSS scrollbar properties. Even, if the page content is more than the browser display area, IE would show transparent or hidden scrollbar as it understands the css properties of the scrollbar but in case of Netscape and Mozilla they will display a scrollbar.



So the need arises to create cross-browser compatible web page windows with no scrollbars to accomplish this purpose we have to take help of little JavaScript code.



Note: But again a drawback is that it will not work on browsers that do not supports JavaScript or have JavaScript turned off.



We will use the window.open method of the javascript which will help us to open a new window with controlled funcationalty.



a small snipet of code will look like

[code]

< a href="javascript:void(0)"onclick="window.open('http://www.msdotnetmentor.com')" >Open a new window < /a>[/code] The open method is of the window object and in the above code it is taking an argument i.e. the ame of the webpage to be opened. and the onclick is a JavaScript event handler which is used to invoke the function in our case.

Bacically the JavaScript window.open() method takes in four arguments.

window.open('URL', 'NAME', 'FEATURES', 'REPLACE')By default, If we provide the filename of a web page through the first argument, it will be loaded in the new window.



NAME: specifies a name for the new window which can be used as value for the target attribute of < a > tags.

FEATURES: let you define properties of the window such as width, height, presence or absence of scrollbars, location bar, status bar etc.

REPLACE: takes a boolean value... we won't bother ourselves with this argument!

[code]< a href="javascript:void(0)"onclick="window.open('http://msdotnetheaven.com','welcome')">Open a new window </a>< a href="javascript:void(0)"onclick="window.open('http://www.msdotnetmentor.com','welcome','width=300,height=200')">Open a new window </a>[/code]List of important FEATURESheight: Specifies height of the new window in pixels. width: width of the new window in pixels location: determines the presence of the location bar menubar: menubar scrollbars: scrollbars status: status bar toolbar: toolbar directories: specifies the display of link buttons resizable: determines whether the window can be resized. If it's absent or its value is set 'no', the window does not have resize handles around its border. fullscreen: Specific to the Internet Explorer, it determines whether the window is displayed in the full screen mode. In the new window please notice that It is not having any scrollbars, location bar, status bar, menubar, toolbar or buttons!
The width and the height take a number (pixels) as value, for other features the value is either a yes or no.

[code]< a href="javascript:void(0)"onclick="window.open('http://msdotnetheaven.com','welcome','width=300,height=200,menubar=yes,status=yes')">Open a new window </a>[/code]


This window has the menu and the status bars. The others are absent since we didn't specify them.

[code]

< a href="javascript:void(0)"onclick="window.open('http://www.msdotnetmentor.com','welcome','width=300,height=200,menubar=yes,status=yes,location=yes,toolbar=yes,scrollbars=yes')">Open a new window </a>
[/code]

The fullscreen feature is specific to this browser and displays the document on the entire screen. A neat effect... sort of! Click on the F11 to remove the full screen display.

[code]
< a href="javascript:void(0)"onclick="window.open('http://www.msdotnetmentor.com','welcome','fullscreen=yes,scrollbars=yes')">Open a full screen window </a>
[/code]

Note: Firefox and Netscape also open a full sized window but show the title bar at top.

Wednesday, March 11, 2009

Transparent or Hide Scrollbar

Transparent or Hide Scrollbar

Sometimes when < body style="overflow: hidden" > property doesnt workswith some broswers then we have the alternative that we must hide it by making it transpernt or coloring it as the page is.

To create a transparent scrollbar or hide it from view, What we need is to work with the css properties of the scrollbar. for our assistance I am here mentionning the cascading style sheet properties.



Note: These properties are recognized by Internet Explorer (5.5 and above) and are ignored by FireFox, Opera and Netscape.



scrollbar-track-color: Sets the color for scroll bar track
scrollbar-face-color: Sets the color for the scroll bar slider
scrollbar-arrow-color: Sets the scroll bar arrow color
scrollbar-3dlight-color: Sets the scroll bar 3D light color
scrollbar-highlight-color: Sets the scroll bar highlight color
scrollbar-shadow-color: Sets the scroll bar shadow color
scrollbar-darkshadow-color: Sets the scroll bar dark shadow color

When does a web page display a scrollbar?
When the content overflows the display area on a browser a web page displays a scrollbar. The controll of the display area on a web browser is monitored and ruled by several factors some of them are the screen resolution, installed toolbars, browser configuration (text size, display of large or small icons), view/hide status bar etc. If the page is long, the browser displays a scrollbar on the right and if the width of the page set at a higher value then the horizontal scrollbar will be added in the browser window.


Sometimes when the page content is less than the display area in a browser.


Different Browsers behave differently if the page fits in the display area. Internet Explorer displays a "grayed" scrollbar while Netscape and Mozilla do not show a scrollbar.



Even if the page content fits nicely in the display area, IE will show a scrollbar. which we may not want to display or just we want to hide it from the user

we have to set the following style properties you may add this in the head section of the page or may use it in external stylesheet



makes the scrollbar transparent.



considering that the page background color is white

[code]

html {
background-color: #FFFFFF;
scrollbar-shadow-color: #FFFFFF;
scrollbar-highlight-color: #FFFFFF;
scrollbar-face-color: #FFFFFF;
scrollbar-3dlight-color: #FFFFFF;
scrollbar-darkshadow-color: #FFFFFF;
scrollbar-track-color: #FFFFFF;
scrollbar-arrow-color: #FFFFFF;
}
[/code]

Note:-- Basically we are setting the color of the scroll bar as the page to give it a feel of transprancy but it will be there

Thanks and Regards
Meetu Choudhary
Founder http://www.msdotnetmentor.com

disable scroll bar

In some cases we would like to disable the scroll bar on the page in that case we can use the following lines in the appropiate section of the .aspx page. the code is as follows

[code]

< body style="overflow: hidden" >



[style type="text/css"]

body {
overflow-x: hidden;
overflow-y: scroll;
}

[/style]

[code]

Note: That all browsers doest not support this method (for instance IE for Mac still shows the scrollbars).

in my next article i will post the code how to handle those browsers...

Thanks and Regards
Meetu Choudhary
Founder http://www.msdotnetmentor.com

Tuesday, March 10, 2009

Show or Hide combobox at Runtime using JavaScript

Show or Hide combobox at Runtime using JavaScript

Many a times in the programming world we feel the need to hide or show the dropdown lists or combo boxes of the particular page or a div or anyother control so here is a small snippet

The Following is the JavaScript function to achieve the above you can embede it in any external JavaScript file or write as an inline script or include in the head section...


function showOrHideAllDropDowns(newState)
{

var elements = document.documentElement.getElementsByTagName('select');

for (var i=0; i
elements[i].style.visibility = newState;
} }




To use the Above function in a div we can write it like


< style="width:220px;" onmouseover="showOrHideAllDropDowns('hidden');" onmouseout="showOrHideAllDropDowns('visible');">





Thanks and Regards
Meetu Choudhary
Founderhttp://msdotnetmentor.com

Saturday, March 7, 2009

Sending Email Through ASP.NET using C#

The following Sample Code is the code which can be used to send mails through ASP.Net C#.... its a working code for me.....

[code]
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.
WebParts;
using System.Web.UI.HtmlControls;
using System.Net.Mail;

public partial class Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
//Calling the function SendMail
Response.Write( SendMail("meetuchoudhary@gmail.com","meetudmeet@gmail.com","meetudmeet@yahoo.com","Test Mail","Test Mail Body"));
}

public string SendMail(string toList, string from, string ccList, string subject, string body)
{
MailMessage message = new MailMessage();
SmtpClient smtpClient = new SmtpClient();
string msg = string.Empty;
try
{
MailAddress fromAddress = new MailAddress(from);
message.From = fromAddress;
message.To.Add(toList);
if (ccList != null && ccList != string.Empty)
message.CC.Add(ccList);
message.Subject = subject;
message.IsBodyHtml = true;
message.Body = body;
smtpClient.Host = "mail.server.com";
smtpClient.Port = 25;
smtpClient.UseDefaultCredentials = true;
smtpClient.Credentials = new System.Net.NetworkCredential("info@server.com", "password");

smtpClient.Send(message);
msg = "Successful";
}
catch (Exception ex)
{
msg = ex.Message;
}
return msg;
}

}
[/code]


--
Thanks and Regards
Meetu Choudhary

Overview of ASP.Net Framework

ASP.NET and the .NET Framework

ASP.NET is part of the Microsoft .NET Framework. To build ASP.NET pages, you need to take advantage of the features of the .NET Framework. The .NET Framework consists of two parts: The Framework Class Library (FCL) & The Common Language Runtime (CLR).

Understanding the Framework Class Library

The .NET Framework contains thousands of classes that you can use when building an application. The Framework Class Library was designed to make it easier to perform the most common programming tasks.
Some Examples are

File class Enables you to represent a file on your hard drive.

Graphics class Enables you to work with different types of images such as GIF, PNG, BMP, and JPEG images.

These are some examples of classes in the Framework. The .NET Framework contains almost 13,000 classes you can use when building applications.

You can view all the classes contained in the Framework by opening the Microsoft .NET Framework SDK documentation and expanding the Class Library node

Subscribe via email

Enter your email address:

Delivered by FeedBurner

MSDotnetMentor

MSDotnetMentor My Website http://msdotnetmentor.com