Shahid Riaz Bhatti

if(my.work == “Interesting” || my.availableTime > my.workHours) { this.blog.Post();}

Javascript Numeric Text Box

June 28
by Shahid Riaz Bhatti 28. June 2010 09:10

Sometime we need to have a text box in our website which only accepts numeric values which may include decimal. To achive this, here is a Javascript function:

 

function NumericTextbox(This, AllowDot) {

var code = event.keyCode;

switch (code) {

case 8: // backspace

case 9: // tab

case 37: // left arrow

case 39: // right arrow

case 46: // delete

event.returnValue = true;

return;

}

if (AllowDot && code == 190) {

if (This.value.indexOf(".") >= 0) {

// don't allow more than one dot

event.returnValue = false;

return;

}

event.returnValue = true;

return;

}

// allow character of between 0 and 9

if (code >= 48 && code <= 57) {

event.returnValue = true;

return;

}

// allow numbers on keypad

if (!event.shiftKey && code >= 96 && code <= 105) {

event.returnValue = true;

// run timeout function to check text on char

var s = "NumericTextbox(document.getElementById('" + This.id + "'))";

setTimeout(s, 250);

return;

}

event.returnValue = false;

}

 

You can copy the above code in your javascript file or in the page itself.

Then you can call this JS function on the keydown event of your text box. Here is the sample.

<input type="text" onkeydown="javascript:NumericTextBox(this,true)" id="txtDecimal" />

 

The Second parameter in the JS function is for decimal. If its true then it will allow decimal , if false then it wont allow decimal..

 

 

Set IFrame Src using JQuery

May 20
by Shahid Riaz Bhatti 20. May 2010 08:54

The following line will set the source of Iframe dynamically  using Jquery.

 var Iframe = $("IframeId");

Iframe.src = "www.google.com";

Thanks for reading.....

C ya

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

ASP.Net | General | Tips and Tricks

GO: Google Launches Its Own Programming Language

November 11
by Shahid Riaz Bhatti 11. November 2009 08:46

One of the core philosophies of Google, and one of the reasons it has been so successful, is efficiency. It’s about both being as efficient as possible when serving search results and processing data and creating product that push the limits of efficiency for the user (as an example, Google’s trying to make communication more efficient with Google Wave).

Maybe that’s why we’re not surprised that GoogleGoogle is finally looking to tackle the underpinning code that runs the web. Today the search giant released Go, an open-source development language that Google believes will combine performance with speed, and one that the company probably hopes will reshape the development and software industries in its favor.

Go is based on the C programming family, one of the most widely used programming language trees in the world. However, the twist is that incorporates elements of Python (a preferred development language within Google) and the Pascal/Modula/Oberon family to make faster and more dynamic programs.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

General

How to show div tags on top of a flash movie

July 27
by Shahid Riaz Bhatti 27. July 2009 07:43

Hi,

Today I encountered an error in which I was having problem of showing contents of <div> tag on the top of a flash movie. I am using div tags as menu to show the menu on hover events. It was working fine till I get a flash movie beneath the menu. In case of flash movie my menu started to disappear behind the flash movie. After doing lil search on google I found the solution which is given below:

You just need to provide the following parameter to the object tag which is displaying the flash movie.

<param name="wmode"value="transparent"/>

I have found this solution after some googling. Here is the link from where I got this solution.

http://www.ravinderweb.com/page/Working-with-Div-and-Flash-Movie.aspx

So follow the above link if you are interested in complete description.

Regards,

Shahid

Currently rated 5.0 by 1 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

General | Tips and Tricks

Filewatcher

May 25
by Shahid Riaz Bhatti 25. May 2009 07:34
 

Working with FileSystemWatcher Class

  

Hey, if you are here to find the answer of this question "how to make sure in Created event of the Filewatcher that the file which is just created is completely copied?" then you are at the right place..

FileSystemWatcher class listens to the file system change notification and raises events when a directory, or file in a directory, changes.. In this article I’ll discuss

fileSystemWatcher1_Created(object sender, FileSystemEventArgs e)  event of FileSystemWatcher class. Working with this event is easy. You just need to capture this event and then write your code in it. BUT there is a problem in this event which is that the Created event is fired immediately as soon as the path of the file is created in the observing directory. This can be clearly explained with the help of a following scenario: I want to observe a Directory say C:\\Test. I wrote a window service which uses the FileSystemWatcher class to observe that directory. I want to pass any new file which is created in this directory to another method which processes this file. Suppose my file’s size is large (e.g. 500mb). In my window service the Created event of the FileSystemWatcher is triggered as soon as the file’s path is created in the directory, but file is not copied completely in the directory. How to solve this issue? .Net does not provide any method or event which can tell me that the file is written completely.  I tried to solve this problem and though I achieved my task, but this is not a good solution.  In the Created event I made a thread. So for each new file a new thread will be created, so we can serve each new file without any delay. In that particular thread, I tried to open the file. If file is opened successfully, then it means that file is copied completely and is available for processing. If not, then try to open the file again. Repeat this process until the file is available. Here is the code: 

void fileSystemWatcher1_Created(object sender, FileSystemEventArgs e)

{   

       Thread _MyThread = new Thread(new ParameterizedThreadStart(this.PerformActualTask));    

       object[] Parameters = new object[] {e. FullPath };    

       _MyThread.Start(Parameters);

 

private void PerformActualTask(object parameters)

  

 //The parameter for this thread body   

 object[] Parameters = (object[])parameters;  

//Full path of the newly created file  

string _SourceFile = (string)Parameters[0];  

int WaitBeforeGiveUp = 300;  

while (true  

     

 try     

        

  //Try to open the file        

  FileStream fs = File.Open(_SourceFile, FileMode.Open);       

  {         

   //We are here because file is successfully opened         

   fs.Close();      

   //Now perform operation on that file      

   }    

 }    

 catch (Exception ex)   

       

  //If exception occured then decriment the wait before give up and ask the thread to sleep       

  if (--WaitBeforeGiveUp > 0)       

        

    // file is not available yet      

  }     

 else     

         

   //if waiting time expired.         

   // SHOW GIVE UP MESSAGE     

 }      //cause the thread to sleep     

 Thread.Sleep(1000);   

} 

}

  

In the code I made some changes which are that I tried to open a file for a particular period of time. If file opened in that period then kool, else I stored a msg in the event viewer that I have given up.     

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

C# | General | Tips and Tricks

RecentComments

Comment RSS

Most comments

supplynflshop supplynflshop
51 comments
tiffany-bracelets tiffany-bracelets
39 comments
AVI to iPad AVI to iPad
36 comments