Friday, December 30, 2011

Prove that programmers too can be social change makers : last day to vote for a social work

A dream to provide solar and computer to a school in rural Nepal! It can be realized by your single vote. Please vote for it at Solar and Computers to a School in Rural Nepal

Appeal from the dreamer - read below please.
My dream is to help a school in an extremely remote village of Western Nepal to buy and install a solar system, batteries, inverters, computers and printers necessary for the school for its computer lab and e-library. The school was built with support from local people and some of the colleges and students of Kathmandu.

Lalu village where the school is located lacks basic infrastructure, however with the local people driving it, the school is a vehicle to bring the community into the 21st century.

The school has very innovative ideas that make it unique. Firstly, Modern Model Residential School is a rural based purely service oriented co-educational English medium primary institution registered as Non-profit Distributing Company. Secondly, it strives to be a progressive institution that acts as a hub for the community, imparting education mixed with modern technology.

Using a pro-rata system the school is able to provide quality education to people of the entire community. Orphaned, disadvantaged or disabled students and families are admitted free of charge, whilst others contribute as little as $3 per month. This shows how even a small amount can change not only the students’ lives but their families and the entire community.

Kalikot is amongst one of the world's most impoverished areas. “57% of people in Kalikot district live under extreme poverty. Per capita income lies at Rs. 6000 (around $ 83) per year and average life expectancy remains at just 42. Only 57.27% of children are literate where as overall literacy rate is at just 38.47%. Still 45.95% of children involve in some kinds of economic activity instead of going to school.” -Central Bureau of Statistics of Nepal, District Profile, Kalikot 2008 AD .
Please don't forget that your single click can make it happen. Time is too short to stop and think. Help to realize the dream and be proud of it! Click Solar and Computers to a School in Rural Nepal to vote!

Yes, programmers too can be social workers!

Thank you!

Tuesday, December 27, 2011

CamStudio - Free Streaming Video Desktop Recording Software

CamStudio a really useful desktop based software that you can use for recording anything that happens with your desktop. And the best part is it is distributed under GNU General Public License (GPL) license. Free to use for both commercial and non-commercial uses. So what are the uses? Let me recite the site itself:
CamStudio is able to record all screen and audio activity on your computer and create industry-standard AVI video files and using its built-in SWF Producer can turn those AVIs into lean, mean, bandwidth-friendly Streaming Flash videos (SWFs) Here are just a few ways you can use this software: You can use it to create demonstration videos for any software program Or how about creating a set of videos answering your most frequently asked questions? You can create video tutorials for school or college class You can use it to record a recurring problem with your computer so you can show technical support people You can use it to create video-based information products you can sell You can even use it to record new tricks and techniques you discover on your favourite software program, before you forget them
How to get the software? How to use this? Yes, it is very easy. Watch the video on how to capture video from your desktop and you are easy to begin! Why this post? Any open source products like this one is a great contribution to the whole world. So this just a give-back to the great effort. I have just tried to spread the word. Could you please do the same? Thank you!

Tuesday, November 22, 2011

Working with dropdownlist or combobox using jquery

More often programmers need to work with dropdownlist or combobox using jquery. We need to manipulate the dropdownlist options using jquery scripting. And it is the case that almost always we don't remember how to implement jquery selector. And for all of my readers, who are enthusiastic programmers and/or designers, and for myself, I am discussing in this post the actions with jquery to manipulate dropdownlist options.

Now append another option using jquery.
[Why am I using the selector syntax $('[id$=ddlTest]') instead of $('#ddlTest')? We use #ControlID to select a control with specified id. $= means 'select a control whose id ends with specified value. If you are using master page, the rendered id of the dropdownlist is preceded with some text.] Now get the selected value from the dropdownlist.
var selVal=$('[id$=ddlTest]').val();
Now get the selected texct from the dropdownlist.
var selTxt=$('[id$=ddlTest] option:selected').text();
Now, select a value programmatically.
var selTxt=$('[id$=ddlTest]').val('Nepal');
And I hope you are comfortable with detecting through jquery when the use selects an item. Good luck!kick it on

Tuesday, October 18, 2011

Missing File menu in visual studio 2010

I just got irritated to see the file menu in visual studio 2010 missing. All other items of the menu, e.g. Edit, View, Refactor, Project, Build etc. were showing. Only mischievous was the File item. It would be of no value for me if only I could add new project in an existing project. But I couldn't find any such option. I had to workout to recover my lost menu item back. And the way is as discussed below.
1. Run Visual Studio Command Prompt for VS2010 as Administrator 2. Navigate to C:\Program Files\Microsoft Visual Studio 10.0\Common 7 3. Run devenv with the option /ResetSettings 4. Press enter This will reset the default settings for the visual studio and open it. Now you see the missing File item. Thanks.

Thursday, September 29, 2011

Disable button in asp net web page to prevent multiple clicks

When a user clicks a button and the response is slow, there are chances that user may click the button again. The scenario may occur both when the button postbacks synchronously or asynchronously. This type of multiple clicks could be prevented if we could just disable the button just after the first click and enable it again when the processing is done. This is quite easy to implement the task in both the cases: synchronous and asynchronous postbacks.
Before we jump on the topic, you may learn how to click a button on enter key press in an textbox control. Similarly you may be interested in displaying google search-like watermark in an textbox control. Both the tutorials help you work with button control more interactively.
Fig. 1: Just after clicking button

Fig. 2: After postback occurs

If you are using ajax processing on button click, just disable the button when it is clicked and enable it when the ajax processing is done. If you are using full postback on button click, you may just make the button invisible using client-side-scripting when the click occurs. And you don't need to worry about making it visible since after postback the page will be rendered again, with the button visible as usual. In the snippet below I have shown how to 'disable' (in fact disabling won't work since the server side event is not firing) the button from client side when it is clicked. 
1. Add reference to jquery file

2. Design the web form
3. Write the client scripting function with jquery

4. The code-behind.
protected void Button1_Click(object sender, EventArgs e)
        lblMsg.Text +="Current time : "+ DateTime.Now.ToLongTimeString()+"

That's all. When you click the button you catch the client side click event and make the button just invisible. Meantime show 'processing' or similar message. If you love ajax loading image, generate one and show it. From codebehind I have just displayed current time in a label.
Happy Bijaya Dashami (Dashain - the greatest festival of Hindus)!
kick it on

Monday, September 26, 2011

Exclusive access could not be obtained because database is in use-sql server restore database error

While publishing a website to the web server, I took backup of my database. Now I had abc.backup at my hand. Next step was to create a database in the sql server of my host. I did it. Then I uploaded the backup file to the server. When I tried to restore the database I got following error:
Exclusive access could not be obtained because the database is in use
This error normally discourages because we wonder what exclusive access is this that we need to successfully restore the database. After searching a while you come to conclusion that the database to which we are restoring our backup is in use by one or some users you have already added. The popular solution is - temporarily isolate the user from the database Easy, if you run this command at your server:
Use master

Alter Database mydbname

 FROM DISK = 'C:\abc.bak'
Now you are right if you suspect whether we should the roll back to multi user. Yes this way:
Use master;


Note that we run the commands against the master database, not the candidate database itself. And did I do the same last time? Nope. I was just happening with a slight mistake. I had created users for the db before I restored the database. So to save yourself from all those stuffs explained above, just create the database in the server, restore your backup file to it and only then create the database users. Done! Thanks.kick it on

Thursday, September 22, 2011

There is a duplicate 'system.web.extensions/scripting/scriptResourceHandler' section defined

Last time I got the following error:
HTTP Error 500.19 - Internal Server Error The requested page cannot be accessed because the related configuration data for the page is invalid.
See in the image below the following config error, and also watch the config source.
There is a duplicate 'system.web.extensions/scripting/scriptResourceHandler' section defined
Root of the error
I got the error when I was deploying a web application precompiled in 2.0 onto the production server with 4.0. The simple search reveals that it is known issues with VS 2010 and 2.0. But my site is 2.0 enabled. What's the root of the error then?  
My conclusion (and please correct me if necessary) I have configured web extension namespaces in my web.config file. You don't see this in 3.5 and 4.0 enabled sites since servers with asp,net 3.5/4.0 by default server ajax services. But 2.0 has to be ajax enabled by installing ajax extension 1.0 which you can download from here. Sensed duplicate entry of system.web.extension section group? Yes, don't include the following section group in the config section if your site runs on 2.0 but published on 3.5/4.0.

Comment out the config section (or remove it if you like), and you are done. Good luck! kick it on

Friday, September 16, 2011

How to add favicon in your asp-net site?

Make your site impressive and standard by displaying favicon. This is a practice of branding also. See in the following image the red circled area at the top corner. The black filled square is the favicon of dotnetspidor: A dot net programming blog. You can see the favicons in almost all of the popular websites.
So how to achieve this? First create a favicon image of your own. Visualize a great logo/image for the favicon. Save it as favicon.ico. Drop it at the root folder of your site. Now you are one step away - just put the following two links just below the title of header of your form. If you are using master page, just put these lines in the master page and you are done for all the pages.


So why the two lines? Normally the first link works. But for some tricky and picky browsers the second link will work. All the best! kick it on

Saturday, September 3, 2011

Delete all stored procedures of a database in sql server

Sometimes there arises the need of deleting all stored procedures of a database. I came across the same situation when I was generating CRUD operations stored procedures via third party tool. I once changed a table and then had to regenerate all the stored procedures. So went on to find out the way. And ultimately stumbled at Here is how to delete all the stored procedures of a sql server database:
USE myDBName
DECLARE @procedureName varchar(500)
      FOR SELECT [name] FROM sys.objects WHERE type = 'p'
      OPEN cur

      FETCH NEXT FROM cur INTO @procedureName
      WHILE @@fetch_status = 0
            EXEC('DROP PROCEDURE ' + @procedureName)
            FETCH NEXT FROM cur INTO @procedureName
      CLOSE cur
      DEALLOCATE cur
All the best! kick it on

Thursday, August 11, 2011

Frequent question on parent and child page refresh, reload, function call in asp-net using javascript

There are ways to call client functions in a parent web page from the child window. This is very helpful in many ways:
1. You can refresh parent page after some updates from child pager
2. You can partially change parts of the parent page
3. You can control the behaviour of parent page from its child (even from iframe child page)

Example? See the way you edit a section in your blogger blog site. When you are logged in and browsing your blog, blogger lets you edit sections of your blog page directly from the public page of your blog. When you click the edit icon, a window will pop up and load with the setting of the editable section. Now when you save your changes the pop up window will close itself and the parent page (your public page) will be refreshed. Want to implement the same?

You can follow these steps:
1. Program your parent page to open new window : You can place a hyperlink in your parent page. There are other several ways to open new window in web page.
2. Call client function in parent page : Now you can call client function in parent page from the child page. I have already posted how to call javascript function in parent web page from child page.
3. Sometimes your child page is a page loaded in iframe from your parent page. In that case it will be a bit different than what I have mentioned in (2). Learn how to refresh parent parent from iframe child page.

I hope this will help tackle the mostly asked questions on parent and child page programming in using javascript.

Happy programming!
kick it on

Tuesday, July 19, 2011

Refresh parent page partially from iframe without reloading the iframe using javascript in

Last time we talked about Refreshing the parent page from child window in using javascript. This technique is useful in many scenarios. (If you haven't been through How to open new window in using javscript and C-sharp, I would like to suggest to read the post thoroughly. After this you will clearly see why the stuff we are talking about in this post is important.) But programmers using iframe to load another web page may wonder if we could only partially refresh the parent page so that iframe keeps itself from reloading. This can by done by calling the parent page javascript function from the child page loaded in the iframe. This way we can even avoid the need of ajax to refresh the parent page without affecting the iframe content. As usual I have presented the simple practical approach to tell you as much clearly as possible - follow please. And before continuing, I would like to inform that there is a post regarding Frequent question on parent and child page refresh, reload, function call in asp-net using javascript that discusses, in aggregate, about some more approaches of parent and child page operations.
Parent Page
I am the parent page.
Page to be loaded in parent page iframe
I am content of iframe page.
Visualize the output
Image: refresh parent page partially from iframe without reloading the iframe using javascript in
What's in the code?
You see a button in the child page that is loaded in the iframe of parent page. On click of the button, the javascript function displayMessageFromIframeChild() of the parent page is called. This function displays the string message from child page in a div of the parent page. That's all. Happy programming!
kick it on

Thursday, July 14, 2011

Refresh parent page from child window using javascript in web application

Much often we open child windows from parent web page. In the child page we perform some activities, and later close the window. At the very time we may need to refresh the parent page so that changes made in the child window be reflected in the parent window. We can easily accomplish this using javascript in web page. Let me show the way using code snippets. If it is your iframe page, you still can refresh the parent page partially from page in iframe (because this will avoid reloading the iframe itself), which I have discussed in another post. And right before following, I would like to inform that there is a post regarding Frequent question on parent and child page refresh, reload, function call in asp-net using javascript that discusses, in aggregate, about some more approaches of parent and child page operations.

Parent web page
Open child window
This is the parent page. Clicking the link will open the child page Child.aspx in a new window. If you wish you can Open the new window in web page in different ways, which I have already discussed in a previous post.

Child web page

This is the child page.

protected void btnOk_Click(object sender, EventArgs e)
        //Implement Your logic here.....
        //now refresh parent page and close this window
        string script = "this.window.opener.location=this.window.opener.location;this.window.close();";
        if (!ClientScript.IsClientScriptBlockRegistered("REFRESH_PARENT"))
            ClientScript.RegisterClientScriptBlock(typeof(string), "REFRESH_PARENT", script, true);        
In the child page, I have just put a button. When the button is clicked, the page logic will be implemented (which I have indicated by the comment lines in the event handler of the button in the child page).

The plus javascript logic
I have just created the javascript stuff that refreshes the parent page of this child page; see the lines:
This line replaces the url of the parent page with its own url - that causes the parent page to reload. And yes, I have registered the javascript code block with ClientScript so that it is executed when the postback life cycle of this child page completes.

Happy programming!
kick it on

Monday, July 11, 2011

C# - Copy files and folders recursively from source to destination folder in c-sharp

In C#, there is no built in function to recursively bulk-copy all files and folders from source to destination folder. So this has to be done manually by the programmer. Being a lover of reusability feature of object oriented programming, I googled and stumbled on the code snippet below:
    /// Copy folder to another folder recursively
    /// /// public static void CopyFolder(string sourceFolder, string destFolder)
        if (!Directory.Exists(destFolder))
        string[] files = Directory.GetFiles(sourceFolder);
        foreach (string file in files)
            string name = Path.GetFileName(file);
            string dest = Path.Combine(destFolder, name);
            File.Copy(file, dest);
        string[] folders = Directory.GetDirectories(sourceFolder);
        foreach (string folder in folders)
            string name = Path.GetFileName(folder);
            string dest = Path.Combine(destFolder, name);
            CopyFolder(folder, dest);
Note that all files at the source folder have been copied to the destination folder. But folder and files within them have been copied using recursion - see the function of second foreach construct.

Shortcomings? Yes, no exception handling has been done in the snippet. However, the functionality is ok! Thanks to

Saturday, June 18, 2011

Page is null at the c# class library control

Hi all.
Just caught up in the mess when I came to see : the parent page of one of my class library control was null at runtime. That means the call:
would fail.

I have been suggested this happens when my parent page is being rendered within an iframe. But this was not the case for now. I was just using a placeholder to dynamically add the control. So what's the solution?

Yes it came around after some googling, try this:


What's in here?

The Page that refers to the Page control containing this dynamic control is achieved through current request handler. This avoids the problem since the request was generated by the page. But mere Page or this.Page or this.Parent.Page or whatsoever might have been missed due to the hierarchy of the controls or is it due to anything else?

Hope this helps. Sweet programming!

Popular Posts

Recent Articles