RSS

Monthly Archives: August 2013

Watermark on TextBox using JavaScript


Some time you need  watermark effect on Asp.net Text Box . then you use this code

JavaScript Code:

 

<script type = “text/javascript”>

    var defaultText = “Enter text here”;

    function WaterMarks(txt, evt)

    {

        if(txt.value.length == 0 && evt.type == “blur”)

        {

            txt.style.color = “gray”;

            txt.value = defaultText;

        }

        if(txt.value == defaultText && evt.type == “focus”)

        {

            txt.style.color = “black”;

            txt.value=””;

        }

    }

</script>

 

Above script will be called on onblur and onfocus events of the  Text Box.

The script does the following two checks

1. If the Text Box is empty and the event type is blur event it sets the watermark and changes the font color as Gray.

2. If the Text Box  matches default text and the event type is the focus it clears the Text Box and sets the font color as Black.

 

<asp:TextBox ID=”txtName” runat=”server” Text = “Enter text here”

    ForeColor = “Gray” onblur = “WaterMarks(this, event);”

    onfocus = “WaterMarks(this, event);”>

</asp:TextBox>

 

if Visual Studio will throw warning when you call client side event in the above way.so you need to call from code behind

txtName.Attributes.Add(“onblur”, “WaterMark(this, event);”);

txtName.Attributes.Add(“onfocus”, “WaterMark(this, event);”);  

 

Advertisements
 
Leave a comment

Posted by on August 29, 2013 in ASP Dot Net C#, Java Script

 

Tags: , ,

Alternating row color on repeater control


<style type=”text/css”>
.normalRow
{
background-color: #FCFCFC;
}
.alternateRow
{
background-color: #ECECEC;
}

</style>

<ul>

<asp:Repeater ID=”rpsize” runat=”server”  >
<ItemTemplate>
<li class='<%# Container.ItemIndex % 2 == 0 ? “normalRow” : “alternateRow” %>’ >

<span><%# Eval(“vchSizeName”) %></span>
</li>
</ItemTemplate>
</asp:Repeater>

</ul>

rowcolor

 
1 Comment

Posted by on August 29, 2013 in ASP Dot Net C#

 

Tags: , ,

How can I make URLs automatically hyperlinked on a web Google Doc


// if you want to open document with google doc viewer thien this article very helpfull for you.

//Header Section

<script>

$(document).ready(function () {
$(‘#document-slider-item’).click(
function (event) {

event.preventDefault();
var url = ‘http://docs.google.com/viewer?url=&#8217;;

url += $(this).attr(‘href’);
url += ‘&amp;embedded=true’;

var iframe = ”;

$(‘#document-viewer’).html(iframe);
});
});
</script>

 

//Body section

 

<body>
<form id=”form1″ runat=”server”>

<a id=”document-slider-item” href=”http://www.irs.gov/pub/irs-pdf/fw4.pdf&#8221; target=”_blank” style=”color:Red;font-weight:bold; font-size:larger;” >Click me</a>
<div style=”float:left” id=”document-viewer”>

</div>
</form>
</body>

 

 

 
Leave a comment

Posted by on August 26, 2013 in ASP Dot Net C#

 

Tags: , ,

remove specific character from column sql


if you want to remove specific character string from string .

like

~/UpLoadedImages/Product20081415160554.jpg

you want to remove ” ~/UpLoadedImages/” this part of string then use this query for that .

UPDATE tblImages
SET vchPath = replace(vchPath, ‘~/UpLoadedImages/’, ”)

 

 

 
Leave a comment

Posted by on August 15, 2013 in SQL Query

 

Generate thumbnails from images in Asp.net


Hi,

This article very helpful for you to generate Thumbnails and also save in Directory path both Actual & thumb image.

 

Client Side:

 

 

<html xmlns=”http://www.w3.org/1999/xhtml”&gt;

<head id=”Head1″ runat=”server”>

<title>Generate a Thumbnails from Uploaded Image</title>

</head>

<body>

<form id=”form1″ runat=”server”>

<div>

<asp:FileUpload ID=”fileupload1″ runat=”server” />

<asp:Button ID=”btnsave” runat=”server” Text=”Upload” onclick=”btnsave_Click” />

</div>

<div>

<h1>Actual Images</h1>

<asp:DataList ID=”DataList1″ runat=”server” RepeatColumns=”3″ CellPadding=”5″>

<ItemTemplate>

<asp:Image ID=”Image1″ ImageUrl='<%# Bind(“Name”, “~/Images/{0}”) %>’ runat=”server” Height=”200px” Width=”200px” />

<br />

<asp:HyperLink ID=”HyperLink1″ Text='<%# Bind(“Name”) %>’ NavigateUrl='<%# Bind(“Name”, “~/Images/{0}”) %>’ runat=”server”/>

</ItemTemplate>

<ItemStyle BorderColor=”Brown” BorderStyle=”dotted” BorderWidth=”3px” HorizontalAlign=”Center”

VerticalAlign=”Bottom” />

</asp:DataList>

<h1>Thumbnail Images</h1>

<asp:DataList ID=”dtlist” runat=”server” RepeatColumns=”3″ CellPadding=”5″>

<ItemTemplate>

<asp:Image ID=”Image1″ ImageUrl='<%# Bind(“Name”, “~/Images/Thumbs/{0}”) %>’ runat=”server” />

<br />

<asp:HyperLink ID=”HyperLink1″ Text='<%# Bind(“Name”) %>’ NavigateUrl='<%# Bind(“Name”, “~/Images/Thumbs/{0}”) %>’ runat=”server”/>

</ItemTemplate>

<ItemStyle BorderColor=”Brown” BorderStyle=”dotted” BorderWidth=”3px” HorizontalAlign=”Center”

VerticalAlign=”Bottom” />

</asp:DataList>

</div>

</form>

</body>

</html>

 

Code Behind:

protected void Page_Load(object sender, EventArgs e)

{

if (!IsPostBack)

{

BindDataListThumbs();

BindDataList();

}

}

 

protected void BindDataListThumbs()

{

DirectoryInfo dir = new DirectoryInfo(MapPath(“Images/Thumbs”));

FileInfo[] files = dir.GetFiles();

ArrayList listItems = new ArrayList();

foreach (FileInfo info in files)

{

listItems.Add(info);

}

dtlist.DataSource = listItems;

dtlist.DataBind();

 

}

 

protected void BindDataList()

{

DirectoryInfo dir = new DirectoryInfo(MapPath(“Images”));

FileInfo[] files = dir.GetFiles();

ArrayList listItems = new ArrayList();

foreach (FileInfo info in files)

{

listItems.Add(info);

}

DataList1.DataSource = listItems;

DataList1.DataBind();

 

}

 

protected void btnsave_Click(object sender, EventArgs e)

{

 

 

string filename = Path.GetFileName(fileupload1.PostedFile.FileName);

// Save Narmal Image

fileupload1.SaveAs(Server.MapPath(“Images/” + filename));

 

string targetPath = Server.MapPath(“Images/Thumbs/” + filename);

Stream strm = fileupload1.PostedFile.InputStream;

var targetFile = targetPath;

//Based on scalefactor image size will vary

GenerateThumbnails(0.07, strm, targetFile);

BindDataListThumbs();

BindDataList();

}

private void GenerateThumbnails(double scaleFactor, Stream sourcePath, string targetPath)

{

using (var image = Image.FromStream(sourcePath))

{

var newWidth = 100; //(int)(image.Width * scaleFactor);

var newHeight = 75;// (int)(image.Height * scaleFactor);

var thumbnailImg = new Bitmap(newWidth, newHeight);

var thumbGraph = Graphics.FromImage(thumbnailImg);

thumbGraph.CompositingQuality = CompositingQuality.HighQuality;

thumbGraph.SmoothingMode = SmoothingMode.HighQuality;

thumbGraph.InterpolationMode = InterpolationMode.HighQualityBicubic;

var imageRectangle = new Rectangle(0, 0, newWidth, newHeight);

thumbGraph.DrawImage(image, imageRectangle);

thumbnailImg.Save(targetPath, image.RawFormat);

}

}

 

 

Download sample code attached

https://skydrive.live.com/?cid=FCCA6A631A7CE903&id=FCCA6A631A7CE903%21886

 

 

 

thumbnails

 
Leave a comment

Posted by on August 6, 2013 in ASP Dot Net C#

 

Tags: , , , , ,