Who is online?  86 guests and 0 members

home » blogs » raghav_khunger

ASP.NET Blogs

CodeAsp.Net's ASP.NET Blogs is more than just a social community for ASP.NET bloggers - we are one of the largest ASP.NET blog directories on the internet. Whether you are looking to search ASP.NET blogs, connect with ASP.NET bloggers, learn more about ASP.NET, or promote your own blog, CodeAsp.Net is for you. Be sure to check back often as we add new ASP.NET blog postings frequently.

Blogs RSS Feed

raghav_khunger : Most Recent postings

Raghav Khunger

Visual Studio: How to stop automatic insertion of ID tags of the controls in ASP.NET

8/27/2010 1:09:50 PM by Raghav Khunger  -  Comments: 1  -  Views: [638]

In this blog I will show how to stop automatic insertion of ID tags of the controls in ASP.NET. In many instances I don't like the automatic insertions of ID tags on my ASPX page, specially with case of literals. For example when you drag your control or double click the control from Visual Studio ToolBox on your form you will see this kind of picture: i.e ID tag is automatically inserted. Now how to stop that ? Below are the steps which will show you how to do it so : Select "Options" from the ...

Read More

Raghav Khunger

ASP.NET: How to add custom controls to Visual Studio toolbox

8/25/2010 1:56:01 PM by Raghav Khunger  -  Comments: 1  -  Views: [875]

In this blog I will show how to add custom controls to Visual Studio toolbox. I always prefer to drag and drop or double click the controls icons from toolbox so that I can use those controls on my page. Now this is fine as per controls which come with Visual Studio, so what to do with the controls made by user own ? how to add them in the toolbox ?. Let's start with making a custom control first. We will make a custom textbox control which will derive from ASP.NET textbox control but will have ...

Read More

Raghav Khunger

List all the files of a particular extension in a directory

8/24/2010 9:01:08 PM by Raghav Khunger  -  Comments: 0  -  Views: [1046]

Yesterday, I saw a person posted a question on forums "How to get list of files having .txt extension inside a directory with c#". I thought I should blog for it. I decided to write a generic method which can be used for any extension. So I made a sample project to demonstrate the same. I have used FileInfo and DirectoryInfo class to achieve it. Below is the sample code: #region Using Directives using System; using System.IO; #endregion public class Example { const string DesiredExtension = "*.t...

Read More

Raghav Khunger

ASP.NET: How to open alert box from codebehind or server side

8/24/2010 9:00:02 PM by Raghav Khunger  -  Comments: 0  -  Views: [877]

Few days back a person asked on the forums on how to open alert box from codebehind or server side. Actually nothing is directly fired from server side in order to show the alert box but actually a script can be registered from server side in the page markup so that as the page loads in the browser an alert is shown. This can be done by "ClientScript.RegisterStartupScript" method. Below is the sample code: <%@ Page Language="C#" ValidateRequest="false" EnableEventValidation="false" %> <...

Read More

Raghav Khunger

Delete all the files and folders with C#

8/24/2010 8:59:57 PM by Raghav Khunger  -  Comments: 0  -  Views: [2041]

Yesterday, I saw a person posted a question on forums “How to delete all the files and folders inside a folder” with C#. I thought I should blog for it. So I made a sample project to demonstrate the same. I made a extension method which will delete all the files and folders inside a particular folder. Before going further you should read this: Source: http://weblogs.asp.net/scottgu/archive/2007/03/13/new-orcas-language-feature-extension-methods.aspx What are Extension Methods? Extension methods ...

Read More

Raghav Khunger

Search a text in all the stored procedures

8/24/2010 8:59:11 PM by Raghav Khunger  -  Comments: 2  -  Views: [706]

Today I was having a requirement where I need to search a text in all the stored procedures in my database. Basically I was in a need to get the list of all those stored procedures which contains a particular text. So I decided to blog for it. Below is the script for it: SELECT [ROUTINE_SCHEMA] , [ROUTINE_NAME] AS [PROCEDURE NAME] , [ROUTINE_DEFINITION] FROM [INFORMATION_SCHEMA].[ROUTINES] WHERE [ROUTINE_DEFINITION] LIKE '%searchtext%' AND [ROUTINE_TYPE] = 'PROCEDURE' ORDER BY [ROUTINE_SCHEMA] ,...

Read More

Raghav Khunger

C#: How to create database through C# code via ADO.NET

8/23/2010 4:08:30 PM by Raghav Khunger  -  Comments: 0  -  Views: [1701]

In this blog I will show how to create a new database through C# code via ADO.Net. In many applications it is needed to create a new database code via frontend so as not to touch the SSMS. Let's start with making a business entity of database object. We will need the following properties DatabaseName, MdfFileName, MdfFilePath, MdfFileSize, MdfMaxFileSize, MdfFileGrowth, LdfFileName, LdfFilePath, LdfFileSize, LdfMaxFileSize, LdfFileGrowth. Below is the source code for it : public class Database {...

Read More

Raghav Khunger

C#: How to get the total size of a directory

8/23/2010 4:07:42 PM by Raghav Khunger  -  Comments: 1  -  Views: [1852]

In this blog I will explain how to get the total size of a directory including all the nested folders and files inside it. In many requirements we need to traverse all the files inside a directory and apply some action on it, therefore I decided to go for a common method for it. This method will accept the directory path and action which is to be applied on each of the files inside that directory. Let's start with the code: #region Using Directives using System; using System.Collections.Generic;...

Read More

Raghav Khunger

ASP.NET: Request format is unrecognized for URL unexpectedly ending in methodname

8/22/2010 9:55:52 AM by Raghav Khunger  -  Comments: 0  -  Views: [1589]

Issue: "Request format is unrecognized for URL unexpectedly ending in methodname" This is the exception which many users get when they try to access web services from their web site running on .Net 1.1 version. From msdn http://support.microsoft.com/default.aspx?scid=kb;en-us;819267 "The .NET-connected Web services support HTTP GET, HTTP POST and SOAP protocols. By default, in .NET Framework 1.0, all three protocols are enabled. By default, in .NET Framework 1.1, HTTP GET and HTTP POST are both ...

Read More

Raghav Khunger

SQL: Display the maximum/largest of each group

8/22/2010 9:33:06 AM by Raghav Khunger  -  Comments: 0  -  Views: [1184]

Many times It Is required to find maximum/largest of count() from various counts on based on particular grouping. In this blog I will explain the same. I have given two samples below one for SQL 2000 and the other for SQL 2005 DECLARE @Test_Max TABLE ( [Id] INT , [Data] VARCHAR(30) , [Amount] INT ) INSERT INTO @Test_Max VALUES ( 1, 'Data1', 10 ) INSERT INTO @Test_Max VALUES ( 1, 'Data2', 20 ) INSERT INTO @Test_Max VALUES ( 1, 'Data3', 60 ) INSERT INTO @Test_Max VALUES ( 1, 'Data4', 15 ) INSERT I...

Read More

Raghav Khunger

jQuery: Change or increase decrease the font size

8/21/2010 4:38:48 PM by Raghav Khunger  -  Comments: 0  -  Views: [2706]

You must have seen the font size controller generally at the top right corner of this web page to increase or decrease the text's font size as per your requirement. In this blog I will show you how to do the same and will show you how to increase or decrease the font size with jQuery. To explain it I have used two input buttons. One for increasing the font size and the other to decrease it. Below is the source code for it: <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title&...

Read More

Raghav Khunger

NOCOUNT in Sql

8/21/2010 4:19:37 PM by Raghav Khunger  -  Comments: 0  -  Views: [959]

Many programmers are unaware of the NOCOUNT feature in Sql. When there is so many DML operations (ie updates and inserts or deletes) it is good to set nocount to on. SQL server can become really talkative when this setting is off ie (SET NOCOUNT OFF), it will consume bandwith and CPU power. Below I am showing you with simple stored procedure on how to use NOCOUNT. GO CREATE TABLE TestTable1 ( id1 INT ) CREATE TABLE TestTable2 ( id2 INT ) GO INSERT TestTable1 VALUES ( 1 ) INSERT TestTable1 VALUES...

Read More

Raghav Khunger

ASP.NET: IPostbackEventHandler VS IPostbackDataHandler Interface

8/21/2010 12:27:23 PM by Raghav Khunger  -  Comments: 0  -  Views: [813]

In this blog I will explain what is the difference between IPostbackEventHandler and IPostbackDataHandler Interface. IPostBackDataHandler: The ASP.NET server control which wants to automatically load the postback data needs to implement this interface IPostBackEventHandler: The ASP.NET server control which wants to handle the postback events needs to implement this interface. Let's start with IPostBackDataHandler interface. Let's create a custom input text control which implements this interface...

Read More

Raghav Khunger

Check uncheck all checkboxes in Gridview

8/20/2010 9:59:05 AM by Raghav Khunger  -  Comments: 0  -  Views: [2113]

In this blog i will show how to check uncheck all checkboxes in Gridview. In many requirements we need a column with checkboxes, and to select all the checkboxes in this column we have one more column in the Header. On selecting this checkbox all the checkboxes in this column are selected and on unchecking the header checkbox all the checkboxes in this column are unchecked. Below is the sample code: <%@ Page Language="C#" %> <%@ Import Namespace="System.Collections.Generic" %> <!D...

Read More

Raghav Khunger

SQL: How to filter rows on the basis of weekday name

8/18/2010 5:36:53 PM by Raghav Khunger  -  Comments: 0  -  Views: [581]

Few days back a person asked on the forums on how to filter rows based on weekday name i.e he was having "sunday","monday" etc as the input parameter and on the basis of that he wants to filter the rows which fall on that day. Below is the solution which I gave: Let's create a user defined function "GetWeekDayNameOfParticularDate". This function accepts the date as input and will return the weekday name of that particular date. Next I chave created a sample table and inserted few records in it a...

Read More

Raghav Khunger

ASP.NET: How to register and use custom control

8/18/2010 4:43:55 PM by Raghav Khunger  -  Comments: 0  -  Views: [551]

In this blog I will show how to register and use custom control in your application. From WikiPedia http://en.wikipedia.org/wiki/ASP.NET#Custom_controls Custom controls Programmers can also build custom controls for ASP.NET applications. Unlike user controls, these controls don't have an ASCX markup file, having all their code compiled into a DLL file. Such custom controls can be used across multiple web applications and Visual Studio projects (which is not allowed with user controls). By using ...

Read More

Raghav Khunger

Windows 7: How to create a VHD file from an existing hard disk

8/16/2010 10:05:00 PM by Raghav Khunger  -  Comments: 1  -  Views: [2463]

In this blog I will show how to create a VHD file from an existing hard disk. Virtual hard disk allows multiple OS to exists on a single host machine. It allows the developers to test their programs or softwares on different OS without the hassle of installing the second hard disk or creating an addition partition to do the same. From Wikipedia ( http://en.wikipedia.org/wiki/VHD_(file_format) ) A Virtual Hard Disk (VHD) is a virtual hard disk file format, meaning that it can contain what is foun...

Read More

Raghav Khunger

Change logon screen in Windows 7

8/16/2010 10:02:54 PM by Raghav Khunger  -  Comments: 0  -  Views: [813]

Today as soon as I started working on my laptop on which Windows 7 is installed, I was welcomed again with the blue screen which comes by default with Windows 7. You might be familiar with the blue logon screen which I am talking about . So I decided to change it and use my own background as I was bored of it. I decided to blog for it. You need to play with a registry item and have to create two new folders. On the right hand side, that was the login screen which I recieved when I restarted my m...

Read More

Raghav Khunger

SQL: How to delete or truncate all the data from all the tables in a database

8/14/2010 7:11:57 PM by Raghav Khunger  -  Comments: 0  -  Views: [732]

In this blog I will show how to delete or truncate all the data from all the tables in a database. In order to accomplish it I have used "sp_msforeachtable" stored procedure. Let me give some brief info regarding that stored procedure. sp_msforeachtable: "sp_msforeachtable" allows you to easily process a particular script against every table in a database. The "sp_MSforeachtable" stored procedure comes with SQL Server, but it is not documented in Books Online. This stored procedure exists in the...

Read More

Raghav Khunger

Javascript: Copy methods from one class to other

7/25/2010 5:57:10 PM by Raghav Khunger  -  Comments: 1  -  Views: [224]

Few days back a person was asking on forums on how to copy the methods from one class to other in Javascript. Yes, it sounds interesting. You can make use of object oriented techniques in Javascript to make robust and well maintained applications. So come to the question which the OP asked. I have created a sample code to accomplish it. In this example I have used a source class (SourceClass.js) , a target class (TargetClass.js) , a utility script (Utility.js) which is having the heart of the co...

Read More

Raghav Khunger

C#: Find the maximum key from a dictionary

7/25/2010 2:44:11 PM by Raghav Khunger  -  Comments: 0  -  Views: [415]

Yesterday a person asked on the forums on how to find the maximum key from a dictionary. He needs to perform some logic after finding the maximum key so I gave him the solution to use Max of LINQ. Below is the code for it : #region Using Directives using System; using System.Collections.Generic; using System.Linq; #endregion public class Example { class Test { static void Main() { var dictionary = new Dictionary<int, string> {{1, "one"}, {2, "two"}, {3, "three"}, {4, "four"}, }; var maxKey...

Read More

Raghav Khunger

Red gates sql prompt: How to stop qualifying the objects name with the owner name

7/25/2010 2:09:58 PM by Raghav Khunger  -  Comments: 0  -  Views: [136]

I like working with "Red Gates" tools, they are awesome. SQL Prompt (one of their tools) is a code auto-completion and formatting tool for writing SQL queries. While working with SQL prompt I noticed that it automatically qualify object names with owner name .i.e if the owner name is "dbo" it makes the query like this: Select * from dbo.mytable As you are seeing dbo has been added while qualifying objects. I need to remove this feature as I don't want to put restrictions on the clients to have t...

Read More

Raghav Khunger

c#:Check for file or directory

7/18/2010 2:31:47 AM by Raghav Khunger  -  Comments: 0  -  Views: [226]

Today a person asked on the forums on how to check or determine whether the physical path he is having is a directory or a file. I told him the solution to go for FileAttributes.Directory property. If this property is true it means we are dealing with directory else with file. Below is the sample code: #region Using Directives using System; using System.IO; #endregion public class Example { class Test { static void Main() { string path1 = @"D:\Foo\foo.txt"; string path2 = @"D:\Foo\"; bool isDire...

Read More

Raghav Khunger

c#: How to replace double backward slash with single backward slash

7/13/2010 5:02:35 AM by Raghav Khunger  -  Comments: 1  -  Views: [296]

Yesterday a person asked on the forums regarding how to replace double backward slash with single backward slash. He was stuck in doing so as there was a need of escaping the backslash which he was missing. I gave him the solution which I have written below: #region Using Directives using System; #endregion public class Example { class Test { static void Main() { //Replacing backward slash string fooString = "This is \\ test \\ string"; string modified = fooString.Replace(@"\\", @"\");//Output: ...

Read More

Raghav Khunger

c#: How to generate n digit unique random numbers

7/8/2010 8:31:08 PM by Raghav Khunger  -  Comments: 1  -  Views: [1631]

In this blog I will explain how to generate n digit unique random numbers in c#. I have used "HashSet" collection and yield keywords in my below example which will help us in to group random numbers. As the random word comes there comes the "Random" class so below is the source code to generate random numbers. #region Using Directives using System; using System.Collections.Generic; #endregion public class Example { class Test { static void Main() { foreach (var number in GetRandomNumbers(10,100)...

Read More

Product Spotlight

ASP.NET Hosting Spotlight

Join CodeAsp.Net for FREE Today!

It's fast, easy and free! Submit articles, get your own blog, ask questions & give answers in the forums, and become a better developer, faster.

enter your email address: