browse by category or date

JavaScript has become more and more important part of Web Application. Often, it does a crucial role such as doing the data verification check on the client side. Quite often also, we use JavaScript to limit the behavior of a field to suit our need. For example, making a textbox to only accept numbers.

But all this fancy ideas will not work if the JavaScript is disabled. To check wheter your user have their Javascript enabled in their environment, add the following snippets into your form:

<head>
<script type="text/javascript">

function checkJavascript()
{ 
    var obj = document.getElementById('javascriptCheck');
    obj.value ="1";
} 

</script>
</head>
<body onload="checkJavascript();">
   <form><input type="hidden" id="javascriptCheck" name="javascriptCheck" value="0" />
       ....
       <!-- put the remaining form in inputs here -->
      ....
   </form>
</body>

 

On the server you will need to check is the ‘javascriptCheck’ variable’s value is ‘1’. If it is, it means Javascript is enabled.

About Hardono

Howdy! I'm Hardono. I am working as a Software Developer. I am working mostly in Windows, dealing with .NET, conversing in C#. But I know a bit of Linux, mainly because I need to keep this blog operational. I've been working in Logistics/Transport industry for more than 11 years.

Possibly relevant:

There are days when we actually need to get the full path location of a file. A quick example would be when you are adding entries into your Book Collector application. After downloads all information about the particular book you are adding, you are then adding the path of the e-Book into the ‘eBook Textbox’ entry. To fill up the entry, you can either browse for the file, or quickly copy and paste the full path location of the file. Usually the latter option is the fastest. Normally, you will do it in the following sequence:

  1. Open ‘Explorer
  2. Navigate the the folder, copy the folder name from address bar
  3. Return back to Book Collector, paste the folder name at the textbox
  4. Return again to Explorer, select the file, press F2/single-click, then copy the filename.
  5. Finally return to Book Collector to paste the filename.

This will become tedious and tiring once you have tens or hundreds entries to key in. So I came up with this solution. The logic of the application will be:

  1. Create a small, transparent floating box which is movable with mouse drag
  2. You can drag and drop a file to this floating box
  3. The full path of that file is copied to the Clipboard
  4. You can go back to Book Collector (or any other use) and paste the full path using Ctrl+V / right-click+paste

Lets tackle the requirement one by one. To create a small, transparent and floating box you need to set the following property:

  • AllowDrop: Change it into True to allow us drag-and-drop object to this Windows Form
  • BackColor: Change it into something cool (which is other than gray)
  • ControlBox: You only need the box. Set it into False
  • FormBorderStyle: Change it to anything but Sizeable.
  • Locked: Set it into True.
  • MaximizeBox: Set it into False
  • MinimizeBox: Set it into False
  • Opacity: This property regulate how transparent is your Windows Form.0% is completely invisible. 100% is not transparent at all. Set the value into around 50%
  • ShowIcon: Set it into False
  • ShowInTaskbar: Set it into False
  • TopMost: Set it into True

Finally modify the constructor to automatically set the size

public Form1()
{ 
	InitializeComponent();
    this.SuspendLayout();
    this.Size = new Size(35, 35);
    this.ResumeLayout();
} 

To allow the window to be moved by dragging, you need to declare class-wide variable and create Event handlers

private bool isMouseDown = false; // to record whether window on dragging mode 
private int oldX; //x-axis position when dragging start 
private int oldY; //y-axis position when dragging start 

// handle MouseDown Event
private void mouseDown(object sender, MouseEventArgs e) 
{
	oldX = e.X; 
    oldY = e.Y;
    isMouseDown = true; 
}

// handle MouseMove Event 
private void mouseMove(object sender, MouseEventArgs e)
{
	if (isMouseDown)
		this.Location = new Point(e.X+this.Location.X-oldX, e.Y+this.Location.Y-oldY);
}

// handle MouseUp Event 
private void mouseUp(object sender, MouseEventArgs e)
{
	if (isMouseDown)
		isMouseDown = false;
}

// handle Keypress Event 
// To close the program when user press 'q' 
private void Keypressed(object sender, KeyPressEventArgs e)
{
	if (e.KeyChar == 'q')
		this.Close();
}

The next step is to take care when a user Drop an object into the form

private void FmDragOver(object sender, DragEventArgs e)
{
	if (e.Data.GetDataPresent(DataFormats.FileDrop) 
	|| e.Data.GetDataPresent(DataFormats.StringFormat))
	{
		if ((e.AllowedEffect & DragDropEffects.Move) != 0)
			e.Effect = DragDropEffects.Move;
		if (((e.AllowedEffect & DragDropEffects.Copy) != 0) 
		&& ((e.KeyState & 0x08) != 0))
			e.Effect = DragDropEffects.Copy;
	}
}
private void FmDragDrop(object sender, DragEventArgs e)
{
	if (e.Data.GetDataPresent(DataFormats.FileDrop))
	{
		string[] astr = (string[])e.Data.GetData(DataFormats.FileDrop);
		Clipboard.SetText(astr[0]);
	}
}

Download the project here:

This solution has helped me save many minutes spend browsing, copy-pasting file’s full path. I hope it help you too.

Reference:
MSDN

About Hardono

Howdy! I'm Hardono. I am working as a Software Developer. I am working mostly in Windows, dealing with .NET, conversing in C#. But I know a bit of Linux, mainly because I need to keep this blog operational. I've been working in Logistics/Transport industry for more than 11 years.

I bump into 3 interesting articles on Digg today. After reading these 3 articles, I can conclude that to get your blog fully exposed to the world you need to follow 3 steps:

  1. Get your blog quickly indexed by the search engines
  2. Optimize your blog to be crawled by the search engines
  3. Make sure you have the right plugin to support point 1 and 2

Get Your Blog Quickly Indexed by the Search Engines

Adam McFarland taught us how to get this on his article. So according to him, there a few steps that fasten indexing of your site. They are:

  • Register your domain name. For cheap domain name, Netfirms always have this cheap $5 .com/.net/.org domain. But Godaddy also offer even cheaper for .info domain which is at $ 0.99 (yes .. 99 cents !!!)
  • Put up a home page. Once you got your domain and hosting, you need to install the Blog software. Since I only have experience with WordPress, I can’t recommed you any other blog software. Personally to me, WordPress is good enough. So many people support it by creating plugins/themes. Because of that, I never look at the other way.
  • Setup a blog and sign up for FeedBurner. The registration is quick and fast. They even let you select the buttons to connect your feed to many RSS Readers.
  • Write a few articles and submit to directories. Adam recommends iSnare and EzineArticles.I think I will submit one of my previous post.
  • Get a link from an indexed site. To do this I participate actively on Google Groups and Digg. Any better idea?

Optimizing WordPress Blogs for Search Engines

Christian Van Den Berge taught us how to get this on his article. So according to him, these steps need to be done to optimise your WordPress blog for search engines indexing process:

  1. Using Permalinks. Permalinks can be setup on your WordPress Admin module. (Option – Permalink).
  2. Put titles up front in your URLs. I use “/%category%/%postname%/” which should have the same effect
  3. Tags. You need to install Ultimate Tag Warrior plugin to enable tags in your blog.
  4. Page Titles. By default, WordPress already set your blog title into “Blog Title – Post Title”. Unless you want to include the tags into the title as mentioned on point 3, you do not need to do anything.
  5. Choose your Post Titles carefully. I believe that in order to be a good post title, the title should be the general idea of the post. I think capitalizing the first letter of every word in the title should make it more attractive.
  6. Autolinks. I don’t use Autolinks. I believer Autolinks might increase the chance of killing my webserver.
  7. Related Post. Use this plugin to add Related Post. Originally, the plugin will use the other posts’ Title as the factor to determine whether they are related. Currently, it has the ability to use keywords for each post. You are very likely need to edit all your previous posts that don’t have keywords.
  8. Ping Services. WordPress 2.1 (the one used here) has an automatic ping service to be signaled whenever you publish a new page. You might want to add the number of ping services through feedburner.
  9. Google Sitemaps. First, submit your site to Google here. Then you submit the site to be reviewed here. You will be required to send an original page or add a meta tag on your header. In my opinion, the latter is the easier one. Then you need to create the xml site map file, you can automatically do that using this plugin. Finally, submit your xml sitemap to Google here.
  10. Categories. Christian‘s idea is that the Categories must be structured such as : “Programming – C# – Threading”.

Legend: : Done : Not (Yet) Done

Hopefully now we have a good understanding on how to get our WordPress blog exposed to the World. The final treat is the list of best plugins for WordPress. Please carefully pick one that really benefits you/suit your needs, without introducing significant increase in the server load.

About Hardono

Howdy! I'm Hardono. I am working as a Software Developer. I am working mostly in Windows, dealing with .NET, conversing in C#. But I know a bit of Linux, mainly because I need to keep this blog operational. I've been working in Logistics/Transport industry for more than 11 years.

Possibly relevant: