Happy New Year to all of you

Hi

The last year was a wonderful year for me. I started blogging on the site in august and its been 4 and a half month and the blog seems to be going bigger and bigger everyday.

In the beginning, the traffic was pretty low, but it has gone up with time, people have started giving their comments on the various posts. But (surprisingly for me) many people have been mailing me with their problem and appreciative comments.

It’s been great to answer those and understand different types of problem that can come up. Also this has helped me a lot in learning a lot of new stuff.

Just for statistics, the site has now got 110 posts in various categories and 75 comments on them.

Some of the most popular blogs have been

Adding_Auto_Suggest_Box_in_the_search_Box.aspx

Continued...

Why not to use cross page post back when validation the page.
Hi

In ASP.Net 2.0 we can use the cross page post back to post to a different page. We can also get the same effect by using the Server.Transfer method. You can look at this post of mine to see how to work around with cross page post back.

But we cannot use cross page post back at every situation. There are some disadvantages of using cross page post back at some situation especially validation.

If we have disabled the client side validation for our controls then the page will post back without any validation. Even if the validation is not turned off, we can’t always use validation on the client (some custom validation controls will only be able to validate servers-side), nor can we always trust the client to perform validation.

Server side validation presents a problem for cross page post backs because our response will come from the destination web form instead of the original web form where the user failed validation. When we inspect the
Continued...

Table variable and temporary table in SQL Server 2000
Hi

In my earlier post I talked about the how we can work with the table variable in SQL Server 2000. But we also have temporary tables in SQL Server 2000 to work with tables. In this post I will discuss the difference between temporary tables and table variables

In SQL server 2000 we cannot use the table variable as an input or output parameter. The table variable is scoped to be stored procedure, batch or any user defined function like local variables. The variable do not exists after the stored procedure exists and hence no need to clean up with a drop statement. But the table variable can be used to return from a user defined function.

Table variable use fewer resource than a temporary table because of there limited scope. Transactions touching table variables only last for the duration of the update on the table variable, so there is less locking and logging overhead. This is also gives better performance to the table variable as against the
Continued...

Table variables in SQL Server 2000
Hi

In SQL Server 2000 there is an alternative to the use of temporary tables. We can use the table variables as an alternative to the table variable. Table variables store a set of records. The declaration syntax looks very similar to a CREATE TABLE statement

DECLARE @Blogs TABLE
(
  BlogID int,
  BlogTitle varchar(100)
)

We can insert some data in the table variable very easily using the select statement to populate data in the table variables.

INSERT INTO @Blogs (BlogID, BlogTitle)
  SELECT BlogID, BlogTitle
    FROM [Blog]

Table variables can be used in batches, stored procedures, User defined functions. We can also use the update and delete keywords with the table variables to modify or delete records.

Here are some examples of working with the table variables.

UPDATE @Blogs
  SET BlogTitle = ‘Changing the data of the blog Title’
WHERE BlogID = 6

DELETE FROM @Blogs
WHERE BlogID =
Continued...

How to save application level settings in windows application
Hi

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.

This means that if we only change the setting value then we will get the changed setting
Continued...

How to take the asp.net 2.0 application offline when required

Hi

Some time when we want to make major changes to our application or we want to gain the access to the resources that cannot be accessed when the web application is running, we want to take the Application offline.

When we are making some major changes to the web application we do not want the user to use the web application. If the user uses the web application when we are changing the database structure and its related code then it might result in problem.

Continued...

How to Register User Controls and Custom Controls in Web.config to manage them easily

Hi

In asp.Net 1.X we had to import and use both customs server controls and user control on a page by adding the @Register directives to the top of the page. Once registered developers could then declare these controls anywhere on the page using the tag prefix and tag names configured in the @Register directive.

This is fine but if we have too many user controls across the sites (and that too ascx files) then it can be painful to manage across the site.

Continued...

A small bit about Impersonation in Asp.Net

Hi

The ability of a thread to execute in a security context different from that of as process owning the thread is called Impersonation.

For web Application this means that if the server is impersonating, it is doing work using the identity of the client that is making the request.

The default setting of the Asp.Net is different from the Asp. By default, Asp.Net does not do pre-request impersonation. The Application can be configured to impersonate on every request with the use of following configuration directive.

<identity impersonate="true" />

Since ASP.NET 2.0 does dynamic compilation, enabling impersonation requires that all accounts have read/write access to the application's Codegen directory (where dynamically compiled objects are stored by the ASP.NET runtime) as well as the global assembly cache (%Windir%\assembly).

Continued...

How to represent a quote within a string in C#

Hi

A very common problem people come-up with while working with string data type is how to work with special character. A number of characters have been labeled as special characters. How would you represent a quote within a string, since the compiler interprets a quote as the beginning or end of the string? Whenever you want to use one of these special characters you need to use a technique known as escaping the character.

Here is a list of the string that needs to be used for the purpose of this special character.

\n = New Line
\r = Carriage return
\r\n = Carriage return and New line
\” = Quotation mark
\\ = Backlash character
\t = Tab

Continued...

Working with different types of socket in Dot net 2.0
Hi
When you are working with the socket class, you can use many socket type. We need to define the type of socket when we create an instance of the socket class. In dot net we have 6 types of Sockets. 
Many a times SocketType implicitly indicates which type of protocolType will be used in the address family. Like when we use the Dgram SocketType the protocoltype will always be Udp. And for Stream SocketType the protocol type will always be Tcp. 
Here is a list of socket types and their uses.
Dgram – This sockettype supports datagrams, which are connection less,
                
Continued...

Working with Cross page post back in asp.net 2.0
Hi 

In Asp.Net, By default the button control posts back to the same page that contain the button. In most of the cases this behavior is ok. But sometime we want to be able to post to another page in the application. In Asp.Net 1.X we used the Server.Transfer method to move between the pages without changing the URL. 

But in Asp.Net 2.0 we can post to a different page, firing a normal post back to a different page inside the application. We can also access the values of the server control of the source page that initiated the post back.

Continued...

Some useful code for windows application

Hi

In this post I am going to talk about some of the small but useful code used (or required) very commonly in the Windows application. 

To get the path to all the Important folders on the client machine, we need to use the System.Envirement namespace. We use the GetFolderPath and pass the value of type Environment.SpecialFolder. This way we can get the path to most of the important folders on the clients machine.

Continued...

Using the Web Browser control to show pop-up like window in Windows application

Hi

Yesterday, a client was asking me to open a pop-up for a link. The problem was that the pop-up window is supposed to be open from a windows application. I knew we can open the browser using the code. The code to that is pretty simple.

System.Diagnostics.Process.Start(URL)

Here is the URL is the URL that should be opened in the browser.  If the URL is empty you will get an exception. 

But what the client wanted was to get a pop-up type display without and buttons, address bar etc…

So I decided to use the in built Web Browser control. The control is pretty simple to use and was more than handy for the purpose. Remember this control is new in the dot net 2.0.

Continued...

Different Features of the click once and windows Installer deployment

Hi 

I dot net 2.0 we have to type of Installation available to us. One is click once Installation and another old Windows Installer method. Both the methods have some advantages and disadvantages. Both the technologies are designed with different set of goals and are not a replacement for each other.

There are many compelling features in Click once deployments which are not present in the windows Installer. These features are specifically targeted at developers building .NET Framework-based smart client applications that don't have sophisticated configuration requirements. On the other hand Windows Installer is a much broader deployment technology that is inherently designed to be extensible and able to handle any deployment challenge, including .NET applications. 

Here is a quick look at the features and the availability in both deployment processes.

Continued...
 
Copyright © 2006 - 2008 Vikram Lakhotia