ITTreats.com
Enter your Search term and Hit "Enter"

Fri, 19 Mar 2010 5:21:14 PM +00:00

Latest 'ITTreats'


Calculate Page Execution time in PHP

Calculate Page Execution time in PHP

For those people who want to give users that in how many seconds actually your web page loaded completely. This script will be useful for you. There are so many ways to do this ( As usual ) but the classic approach would be

Step 1 : make a note of  the time when your page get starts

Step 2: make a note of  the time  at the end of your total page execution

Step 3 : step 2 – step1, You will get your page execution time

In simple   Here is the function  which will do it for you .

You have  to   call the function at the  start  and   echo  it  at the  end.   simple !!!!

More . . .

Paginating in ASP

Paginating in ASP

Pagination in asp, plays major roll when you want to display page wise results , what if the recordset size is more or huge, in that case the processing of the page will become slow…

For that here is the query , which will really help you

the following query is MSSQL query

For example if you want employee name whose
salaries are 2nd highest and 1oth highest

Now,

step 1 :select *, ROW_NUMBER() over ( salary desc) as ROWID from emp

step 2 : supply the above query as sub query

select * from ( select *,ROW_NUMBER() over (salary desc) as ROWID from emp ) where rowid between 2 and 10

thats it .. now you will get emploee list from 2nd highest salary to 10th highest salary ,,,,

by making use of the above query in pagination purpose, then your page will never slow down becoz, we are putting only 10 to 100 rows at max ,

Creating and Using Own Templates using ASP

Creating and Using Own Templates using ASP

When ever the scripts on your pages will become complex, Templates are the best solution.

working on ASP Templates is quite easy,

1. Stick to page layout
eg:. pregare a static html page with your requirements
2. change the content part of each division to one standard identification string
eg:.

<div id='leftpanel'>
    <ul>
          <li>1</li>
<li>1</li>
<li>1</li>
<li>1</li>
<li>1</li>
</ul>
</div>

where ul is the dynamically generated content

change it to
<div id=’leftpanel’>
<!-leftpanel->
</div>

3. Now write a function with the final html code

Function htmltemp()
template = “”
template = template & “<!-title->”
template = template & “”
template = template & createBody()
template = template & “”
template = template & “”
htmltemp = template
End Function

FUNCTION createBody()

bodytext =bodytext &”<!-header->”
bodytext =bodytext & “<!-menunavigation->”
-
-
-
createBody=bodytext
End Function

like this go on creating functions for the necessery blocks and combine them to form a dynamic HTML content

finally integrate this in the page where needed as shown below :

File : finaltemplate.asp

<% thetitle = “HTML Template”
thebody = “<CENTER> This is the template! </CENTER>”

template = htmltemp()
template = Replace(template, “<!-title->”, thetitle)
template = Replace(template, “<!-body->”, thebody)
Response.Write template

Function htmltemp()
template = “<HTML>”
template = template & “<TITLE><!-title-></TITLE>”
template = template & “<BODY>”
template = template & “<!-body->”
template = template & “</BODY>”
template = template & “</HTML>”
htmltemp = template
End Function

%>

How to Make Read only Check Boxes

How to Make  Read only Check Boxes

How we can make a Chek box readonly? Even if we provide Readonly attribute you still can check or uncheck the checkbox..

then how we can make a CheckBox ReadOnly ??
Here is the simple solution,  we can do this  with Javascript. here is how it goes

write a onclick even for the desired checkbox, and  check weather it is checked , if it is check then make that checked as false vice versa

<input type=\”checkbox\” value=\”xyz\” checked onclick=\”javascript:if (this.checked==true) this.checked=false; else this.checked=true;\” />

Here is the example Below :

Try to Uncheck Me :

Simple is\’t it ??

Adding Sub MenuItems to the Context Menu Item Dynamically

Adding  Sub MenuItems to the Context Menu Item Dynamically

You can’t add sub menuitems to a Context Menu Item Programatically for more than one time.

If you try to add first sub menu item it will add up into the list then again if you try to add then the sub menu items wont be displayed,

but if you debug it you will find the Submenu Items will still there .

This is Bug in .NET to over come this problem , toggle the visiblity of the added menuitem submenuitem1.visible=false; submenuitem1.visible=true;

Strip HTML tags ,Script blocks,Forms, style blocks using Regex in C#.net

Strip HTML tags ,Script blocks,Forms, style blocks  using Regex in C#.net

Many times in Many cases we may come across this problem how to strip HTML Tags,

How to Remove Script Blocks ? How to remove Form Blocks and how to remove Style sheet blocks ?

for those questions here is the simple and best answer More . . .

Processing Web Request from c#.net/vb.net

Processing Web Request  from c#.net/vb.net

To process  web request from c#.net/vb.net windows application we have  WebRequest Class.

import  System.Net,System.IO name spaces  for requesting and processing the result

here is the example code

1. create a uri with the required URL   Uri wsn=new Uri(\”http://www.ITTreats.com\”);

2.Next  create a webRequest class and pass the above uri object to it   WebRequest wr=WebRequestFactory.Create(wsn)

3.  Now, capture the response of the  address   WebResponse wresp = Wr.GetResponse();

4. assaign the data to stream   StreamReader  sr=new StreamReader(wresp.GetResponseStream(), Encoding.ASCII);

5. Proceed with your further  coding requirements

How to Hide when form is minimized

How to Hide when form is minimized

To Hide a Form when minimize button is pressed, we have to write a event for Form Sized Changed event in that,
add this condition

if (this.WindowState == System.Windows.Forms.FormWindowState.Minimized) { this.Visible = false; }

working with Notify Icon and Context menu

working with Notify Icon and Context menu

Working with  Notify Icon and Context menu is simple
please follow the  steps

1. Drag and Drop the NotifyICon, Context Menu from the Tool Box

2. Change the names and text of the controls

3. Now, Create the Required Menu  for the COntext menu
for eg: add the Cut,Copy,Paste,Delete  Menuitems to the  context Menu

4. Now  Attach this context menu to the notify icon ,  by  selecing the  appropriate context menu  ,   You can do this  from the properties of the Notify Icon, change the appropriate context menu name.

Now  handle the  Proper Events  depending on your requrement for contextmenuitems

!! Happy Coding !!