Wednesday, December 17, 2008

Check a value in a string using Javascript

In .net if we want to check a value whether it is existing in given string
we have contains function which return true or false.
But in javascript we dont have function like this.But we can implement this
by using the function indexOf()

All you need to do is check whether the return value is -1 or not. A return value of -1 implies that the specific letter is not present in the given string.

function checkString()
{
if(str.indexOf("http://")==-1)
{
alert("Value Not Found");
}
else
{
alert("Value Found");

}
}

Monday, December 8, 2008

Random results

This is related to sqlserver.
Our team recently completed a project for a Real estate company, for which we received thank-you letters and e-mails from very happy customers.we have stored this in a table.
we want to show this on page. We chose to display 10 notes, but we didn't want a fixed display because it would be boring and require maintenance. So, we opted to display 10 notes selected at random.

To do this just we have used a simple query which displays
different result at diffent times.

select top 3* from table name order by newid()

Friday, December 5, 2008

Find control in aspx page which has master page

Its easy to find the control in apsx page but we need to write
extra code when we have a master page for the aspx page.

Below is the code which finds control in aspx page which has master page.

Dim content As ContentPlaceHolder
content = Page.Master.FindControl("ContentPlaceHolder1")

Dim labelcontrol As Label
labelcontrol = content.FindControl("LabelId")
labelcontrol .Visible = False


using above code we can find the control.

Thursday, December 4, 2008

Yesterday Date in Sqlserver

Below is the query to get Yesterday date in sqlserver.

Select *
from table
where DATEPART(dd,creationdate) = datepart(dd,dateadd(dd,-1,getdate()))
and datepart(mm,creationdate) = datepart(mm,dateadd(dd,-1,getdate()))
and datepart(yyyy,creationdate) = datepart(yyyy,dateadd(dd,-1,getdate()))

Thursday, November 6, 2008

favicon to your site

Would you like to display your own icon on the browser address bar when visitors view or bookmark your web page?
place the below code in the head tag of page to get the icon.

<link rel="shortcut icon" href="http://path/favicon.ico" >
<link rel="icon" href="http://path/favicon.ico" >

To Genearate favicon to your site click here

Tuesday, November 4, 2008

Fire a button click from any text box when enter key is pressed

If you have more than one button on a form ASP.Net doesn't know which button should be the default button.

With this code you may trigger any button click from any text box when the enter key is pressed.

TextBox.Attributes.Add("onkeydown", "javascript:if((event.which && event.which == 13) || (event.keyCode && event.keyCode == 13)){document.getElementById('" & Button.ClientID & "').click();return false;}else return true;")

other way is if you are using panels then you can use the property
"Default Button".

Wednesday, October 29, 2008

WebControl for creating charts

Check this Url.
http://www.carlosag.net/Tools/WebChart/

its an excellent free chart control to render charts in our application.

Redirecting to Custom Error Page When 404 Page not Found Occurs.

Write the below code in global.asax file in Application_Error Method.
StringBuilder errMessage = new StringBuilder();
Exception ex = Server.GetLastError();
if (ex is HttpException)
{
HttpException checkException = (HttpException)ex;

switch (checkException.GetHttpCode())
{
case 403:
{
errMessage.Append("You are not allowed to view that page.");
break;
}
case 404:
{
errMessage.Append("The page you requested cannot be found.");
break;
}
}
}

we can number of http code here.

Get the Previous Page Name

Below is the code to get page name from where it has been redirected to the current page.

code in the current page:

if (Request.UrlReferrer != null)
{
string PName = Request.UrlReferrer.Segments[Request.UrlReferrer.Segments.Length - 1];
Response.Write("Redirected from : "+PName);
}


lazer hair removal

Thursday, October 23, 2008

Detecting Browser Pop up blocker.

Below is the javascript code to detect the popup blocker of a browser
<script language="javascript">
function popupblocker()
{

var sOption="toolbar=no,location=no,directories=no,menubar=no,";
sOption+="scrollbars=yes,width=500,height=500,left =200,top=50";
var i=window.open("Somepage.aspx","",sOption);

if(!i)
alert("Your browser Popup is on,Please turn off to open the child window.")


}

</script>

call this function on body load.

<body onload="popupblocker()">
</body>

Tuesday, October 21, 2008

Getting Image coordinates on mouse move.

<html>
<head>
<script language="JavaScript">
function point_it(event)
{
pos_x = event.offsetX;
pos_y = event.offsetY;
document.pointform.form_x.value = pos_x;
document.pointform.form_y.value = pos_y;
}
</script>
</head>
<body>
<form name="pointform" method="post">
<img src="Sunset.jpg" id="cross" onmousemove="point_it(event)"/>
You pointed on x = <input type="text" name="form_x" size="4" /> - y = <input type="text" name="form_y" size="4" />
</form>
</body>
</html>

Thursday, October 16, 2008

Images Resize

Below is code to resize the image in terms of its height and width and also its filesize.


System.Drawing.Image src_image = System.Drawing.Image.FromStreamFileUpload1.PostedFile.InputStream);

Bitmap bitmap = new Bitmap(Width,Height,System.Drawing.Imaging.PixelFormat.Format24bppRgb);

bitmap.SetResolution(src_image.HorizontalResolution, src_image.VerticalResolution);

Graphics new_g = Graphics.FromImage(bitmap);

new_g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;

new_g.InterpolationMode = System.Drawing.Drawing2.InterpolationMode.HighQualityBicubic;

new_g.DrawImage(src_image, 0, 0, bitmap.Width, bitmap.Height);

src_image.Dispose();

bitmap.Save(Server.MapPath(URL) + FileUpload1.FileName.ToString(), System.Drawing.Imaging.ImageFormat.Jpeg);

bitmap.Dispose();

new_g.Dispose();


The Above Code is for Only Jpegs.

List of Connection strings for different Databases from .Net

Ms-Access :

Provider=Microsoft.Jet.OLEDB.4.0DataSource=C:\mydatabase.mdb;UserId=admin;Password=;


Sql server :
Data Source=myServerAddress;Initial Catalog=myDataBase;User Id=myUsername;Password=myPassword;

My Sql :
Provider=MySQLProv;Data Source=mydb;User Id=myUsername;Password=myPassword;

Oracle :
Provider=msdaora;DataSource=MyOracleDB;UserId=myUsername;Password=myPassword;

For More Connection Strings Click Here

About Sql server Injection through Query strings.

ASCII Encoded/Binary String Automated SQL Injection Attack

Check out the below link to know more how it works.

http://www.bloombit.com/Articles/2008/05/ASCII-Encoded-Binary-String-Automated-SQL-Injection.aspx

Indexes in Sql server

Indexes in SQL server are similar to the indexes in Books.
They help SQL server retrieve the data quickly.

There are clustered and nonmclustered indexes.

A clustered indexes is a special type of index that records the way in which records in the tableare physically stored.Therefore , table can have only one clustered index.The leaf nodes of a clustered index contain the data pages.

A nonClustered index is a special type of index in which the logical order of the indexdoes not match the physical stored order of the rows on disk.The leaf node of a non clustered index dows not consist of the data pages .Instead the leaf nodes contain index rows.
The syntax for creating indexes

CREATE INDEX idxModelON Product (Model)

Let's assume that we have the following table,

TABLE Customer
(
First_Name char(50),
Last_Name char(50),
Address char(50),
City char(50),
Country char(25),
Birth_Date date)


and we want to create an index on the column Last_Name, we would type in,

CREATE INDEX IDX_CUSTOMER_LAST_NAMEon CUSTOMER (Last_Name)[/COED]

If we want to create an index on both City and Country, we would type in,

CREATE INDEX IDX_CUSTOMER_LOCATIONon CUSTOMER (City, Country)