Pass Value(databinder.eval) to Javascript Function

July 15, 2009

In some scenario we have to call Javascript Function with dynamic parameter values.

Take a scenario in which we have to pass variables to javascript on ‘onchange; event of Textbox which is in TemplateColumn of gridview.

Here is the Small Example for the same.

I have a Javascript Function with the name ‘processRequest’ with three Parameters like sender of type object, columnName of type string and ID of type int. i want to call this function while user has changed text in Gridview Textbox.

Here is my Javascript Function’s Decalration:
function processRequest(sender,columnName,ID)
{
var Values = sender.id+”/@,@,@/”+sender.value+”/@,@,@/”+columnName+”/@,@,@/”+Qid;

alert(Values);
}

now to call this function i have added ‘onchange’ event of the Textbox like this:

ProcessRequest

Thats it!!!!

Note : i have known the ASCII character for the Single Quote from HERE


Search Text in Database’s Objects

July 14, 2009

Here is the SQL Stored Procedure which will list all the database’s Objects(SP, Views, Functions etc…) in which the Searched Text exist.

CREATE PROCEDURE [dbo].[SearchTextInDatabase]
@SearchText VARCHAR(200)
AS
BEGIN
— SET NOCOUNT ON added to prevent extra result sets from
— interfering with SELECT statements.
SET NOCOUNT ON;
DECLARE @SQL VARCHAR(MAX)

SET @SQL = ‘SELECT Name FROM SysObjects WHERE ID IN
(SELECT ID FROM SysComments WHERE Text Like ”%’ +   @SearchText + ‘%”)
ORDER By Name’

EXEC(@SQL)
END

/*
Here is the Example How to use it….. 🙂

EXEC [SearchTextInDatabase] ‘SearchText’

*/


List Object’s Properties in Javascript

July 8, 2009

Here is the Code to List all the Properties of an Object in JavaScript

for (var propertyName in Object)
{
    document.writeln(propertyName);
    document.write(‘<BR>’)
}

Note:- Object will be replaced by your objectName 🙂


Resize Bitmap Image with Aspect Ratio

July 4, 2009

Just Copy this function into your code and use it to resize the bitmap image with corresponding aspect Ratio.

private Bitmap ResizeImage(Bitmap image, int width, int height)
{
Bitmap OriginalBmp = image;

int OriginalWidth = OriginalBmp.Width;
int OriginalHeight = OriginalBmp.Height;
int OriginalX = 0;
int OriginalY = 0;
int NewX = 0;
int NewY = 0;

float Percent = 0;
float WidthPercent = 0;
float HeightPercent = 0;

WidthPercent = ((float)width / (float)OriginalWidth);
HeightPercent = ((float)height / (float)OriginalHeight);
if (HeightPercent < WidthPercent)
{
Percent = HeightPercent;
NewX = System.Convert.ToInt32((width – (OriginalWidth * Percent)) / 2);
}
else
{
Percent = WidthPercent;
NewY = System.Convert.ToInt32((height – (OriginalHeight * Percent)) / 2);
}

int DestWidth = (int)(OriginalWidth * Percent);
int DestHeight = (int)(OriginalHeight * Percent);

Bitmap NewImage = new Bitmap(width, height, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
NewImage.SetResolution(OriginalBmp.HorizontalResolution, OriginalBmp.VerticalResolution);

Graphics Gr = Graphics.FromImage(NewImage);
Gr.Clear(Color.White);
Gr.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;

Gr.DrawImage(OriginalBmp, new Rectangle(NewX, NewY, DestWidth, DestHeight), new Rectangle(OriginalX, OriginalY, OriginalWidth, OriginalHeight), GraphicsUnit.Pixel);
Gr.Dispose();
OriginalBmp.Dispose();
MemoryStream Ms = new MemoryStream();
return NewImage;
}