Check if variable exists in Javascript

I was facing a problem in javascript when I define a variable dynamically. I wanted to check whether that variable exists or not. A solution for the same is as below :

if(typeof(strName) == ‘undefined’)
         … do anything

where strName is an undefined variable.

Comments (5)

SQL Server CE (Compact Edition) Database

SQL Server CE is a small, in-process database that provides the essential features of a relational database and is intended for desktop and mobile applications that need a local data store but do not require the full functionality of SQL Server. Each database is stored in a file that, by default, has an .sdf extension. 

For SQL Server CE, opening a connection opens the database file. As a result, creating and releasing connections for each request would be quite slow. To avoid these performance problems, an application that uses SQL Server CE typically keeps a connection open for as long as it uses the database.Consequently, SQL Server CE does not support stored procedures. If you try to use any of the Execute methods, such as ExecuteScalar and ExecuteNonQuery, that include a stored procedure as a parameter, the application block throws an exception. Instead of stored procedures, you can use in-line SQL statements. There are Execute method overloads that accept a SQL statement as a parameter. For the same reason that stored procedures are unsupported, you can only send one SQL statement in a request.

It now includes a new overload of the Database.UpdateDatabase method that uses the updateBatchSize parameter. Setting the UpdateBatchSize parameter to a positive integer value causes the DataAdapter object to send updates to the database as batches of the specified size. This reduces the number of database round trips.

Source : MSDN

Leave a Comment

IE Developers Toolbar – Good to have IT !

Recently while surfing I found a IE Developers Toolbar which I found of much useful to developers. You can get your copy :
http://www.microsoft.com/downloads/details.aspx?FamilyId=E59C3964-672D-4511-BB3E-2D5E1DB91038&displaylang=en

Leave a Comment

Capture Screen using C#

private Bitmap screenBitmap; // It will grab the size of your current screen.
Rectangle screenRegiion = Screen.AllScreens[0].Bounds;

 // It will create the bitmap of the specified region.
screenBitmap = new Bitmap(1024, 768, PixelFormat.Format32bppArgb);

// It will copy the current screep image to the bitmap image.
Graphics screenGraphics = Graphics.FromImage(screenBitmap);
screenGraphics.CopyFromScreen(screenRegiion.Left, screenRegiion.Top, 0, 0, screenRegiion.Size);

screenBitmap.Save(@”c:\test.bmp”);

Comments (2)

Use gmail Account as pop3 and smtp in ASP.NET

Do you know ???
You can use your gmail account as a pop3 and smtp in ASP.NET or win applications …… You might need to enable your smtp and pop3 from your account.

SMTP: smtp.gmail.com
PORT : 587

POP : pop.gmail.com
PORT : 995

Leave a Comment

Extension Method : A New Orcas Feature

Extension methods allow developers to add new methods to the public contract of an existing CLR type, without having to sub-class it or recompile the original type.  Extension Methods help blend the flexibility of “duck typing” support popular within dynamic languages today with the performance and compile-time validation of strongly-typed languages.

Using the new “extension method” language feature in C# and VB, I can instead add a useful ”IsValidEmailAddress()” method onto the string class itself, which returns whether the string instance is a valid string or not.  I can then re-write my code to be cleaner and more descriptive like so:

string email Request.QueryString["email"];
if 
( email.IsValidEmailAddress() ) {   }

How did we add this new IsValidEmailAddress() method to the existing string type?  We did it by defining a static class with a static method containing our “IsValidEmailAddress” extension method like below:

public static class infovishExtensions
{
    
public static bool IsValidEmailAddress(this string s)
    {
        Regex regex 
= new Regex(@”^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$”);
        return 
regex.IsMatch(s);
    
}
}

Note how the static method above has a “this” keyword before the first parameter argument of type string.  This tells the compiler that this particular Extension Method should be added to objects of type “string”.  Within the IsValidEmailAddress() method implementation I can then access all of the public properties/methods/events of the actual string instance that the method is being called on, and return true/false depending on whether it is a valid email or not.

To add this specific Extension Method implementation to string instances within my code, I simply use a standard “using” statement to import the namespace containing the extension method implementation:

using infovish;

The compiler will then correctly resolve the IsValidEmailAddress() method on any string. Just write in like :

if ( email.IsValidEmailAddress(“infovish@infovish.com”) ) { } ………
Read from : http://msdn.microsoft.com/dotnetrocks/

Leave a Comment

Problem with ClientScript.RegisterClientScriptBlock when using Ajax

There’s a breaking change in the beta. to insert scripts during a partial postback youmust use the registerXXX static methods of the scriptmanager class. 

e.g.
Microsoft.Web.UI.ScriptManager.RegisterClientScriptBlock(DropDownList1, typeof(DropDownList),“TestKey”,” alert(‘TEst Key’); “,true);

Comments (6)

Missing Intellisense within ASP.NET AJAX Controls

Sometimes Markup intellisense no longer works for controls or for any controls nested within ajax controls. We discovered a bug with the VS markup intellisense engine when doing the ASP.NET AJAX Beta1 release – which is that you lose intellisense when you map multiple assemblies against the <asp:> tag prefix and use the controls within a <asp:content> control in a .aspx page based on a master page. 

Preferred Solutions :

1) . Either Install VS SP1.
2). Let Master Page open. It turns out the intellisense engine only runs into issues if the .master file is closed.  As long as it is open within the same IDE, it resolves the assemblies just fine and will give you full intellisense.
3). Change Tag Prefix <asp> to any other tag, lets say <ajx> in web.config.

Comments (1)

Saving Application settings in a Windows Application

Many a times in the windows application when you create some settings, we ned to save the settings so that it can be retrieved and used when the user starts the application again. In Dot net this can be done very easily.

You need to save these settings in the Application settings. The scope of these setting should be user and not application. Remember the Settings with the scope of Application are readonly and hence these cannot be changed in the code.

Now to retrieve the settings use the following code

Properties.Settings.Default["SettingName"].ToString();

To change the settings for the user you need to

Properties.Settings.Default ["SettingName"] = “Value”;
Properties.Settings.Default.Save();

The setting is changed by setting the property value. But if you do not save the setting the changed setting will not be available next the application restart.

Leave a Comment

How to send mail in Asp.Net 2.0 with read receipt

Many a time we want to add read receipt header to the Email we sent. A read receipt is a notification method where by an Email is sent to the given Email address when the mail is first read. To add a read receipt Notification to the Email in Asp.net we need top add the header Disposition-Notification-To in the Email. This can be done very easily by one line of code.

mail.Headers.Add("Disposition-Notification-To", "<EmailAddress@mydomain.com>");

If we add this header to the element the read receipt Email will be sent to the EmailAddress@mydomain.com.

Although this header is recognized by most of the mail clients, this might not work with all the mails. There can be many reason for this. The mail client may not recognize the header and hence not send any notification.

Comments (2)

« Newer Posts · Older Posts »