Feed on
Posts
Comments

Have you tried using JavaScript confirm() function in ASP.NET Button, LinkButton or ImageButton client onclick property?

<asp:LinkButton ID="lbtnDelete" runat="server" CommandName=’DeleteItem’ Text=’Delete’ OnClientClick="confirm (’Are you sure you want to\ndelete this item?’);" ></asp:LinkButton>

But even if you click OK in the confirm dialog the page is not submited because the next JavaScript code for submitting the page (like WebForm_DoPostBackWithOptions) is not executed. The solution is using:

if(!confirm(‘your text’)) return false;

Instead of the code above I use:

<asp:LinkButton ID="lbtnDelete" runat="server" CommandName=’DeleteItem’ Text=’Delete’ OnClientClick="if(!confirm (’Are you sure you want to\ndelete this item?’))return false;" ></asp:LinkButton>

, , ,
Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • del.icio.us
  • dzone
  • Netscape
  • digg
  • YahooMyWeb
  • Technorati

Recently I found new bug in MS WebResource.axd javascript. The problem is that when using a browser like Firefox and a multiline textbox is put inside panel with DefaultButton set, pressing the enter button while editing text in the textbox submits the form instead of going to new line.
 
The fix that I’ve found is this JavaScript function that accepts the textbox client id as parameter:

function PreventSubmitOnKeyPress(sObjectID) {
    try {
        if (!document.all) {
            var oObject = $id(sObjectID);
           
            if (oObject.addEventListener) { 
                oObject.parentNode.addEventListener("keypress",
                    function(e) {
                        if (e && e.keyCode && e.keyCode==13) {
                            e.stopPropagation();
                        }
                    }, false); 
            } 
        }
    } catch (e) {}
}

 
To call the function you can use something like that:

<script type="text/javascript">
var sMyTextBoxID = ‘<%=txtMyTextbox.ClientID %>’;
PreventSubmitOnKeyPress(sMyTextBoxID);
</script> 

, ,
Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • del.icio.us
  • dzone
  • Netscape
  • digg
  • YahooMyWeb
  • Technorati

Creating thumbnails with .NET is really simple task. You have to call only one method Image.GetThumbnailImage(). The problem is that the quality of the created image is really poor. So I’ve started googling around and the result is this GenerateImageThumbnail() function:

    public static void GenerateImageThumbnail(Stream streamImage, string sThumbnailImagePath, int nMaxWidth, int nMaxHeight)
    {
        Image oImage = Image.FromStream(streamImage);

        GenerateImageThumbnail(oImage, sThumbnailImagePath, nMaxWidth, nMaxHeight);
    }

    public static void GenerateImageThumbnail(string sImagePath, string sThumbnailImagePath, int nMaxWidth, int nMaxHeight)
    {
        Image oImage = Image.FromFile(sImagePath, true);

        GenerateImageThumbnail(oImage, sThumbnailImagePath, nMaxWidth, nMaxHeight);
    }

    public static void GenerateImageThumbnail(Image oImage, string sThumbnailImagePath, int nMaxWidth, int nMaxHeight)
    {
        float fRatio = 1;
        int nWidth = oImage.Width;
        int nHeight = oImage.Height;
       
        //calculate the thumb image size if needed
        if (oImage.Width > nMaxWidth || oImage.Height > nMaxHeight)
        {
            if (oImage.Width >= oImage.Height)
            {
                fRatio = ((float)oImage.Height) / ((float)oImage.Width);
                nWidth = nMaxWidth;
                nHeight = Convert.ToInt32(nMaxHeight * fRatio);
            }
            else
            {
                fRatio = ((float)oImage.Width) / ((float)oImage.Height);
                nWidth = Convert.ToInt32(nMaxWidth * fRatio);
                nHeight = nMaxHeight;
            }
        }               

        //create the thumbnail ans set it’s settings
        Image oThumbnail = new Bitmap(nWidth, nHeight);
        Graphics oGraphic = Graphics.FromImage(oThumbnail);

        oGraphic.InterpolationMode = InterpolationMode.HighQualityBicubic;
        oGraphic.SmoothingMode = SmoothingMode.HighQuality;
        oGraphic.PixelOffsetMode = PixelOffsetMode.HighQuality;
        oGraphic.CompositingQuality = CompositingQuality.HighQuality;

        oGraphic.DrawImage(oImage, 0, 0, nWidth, nHeight);

        //save the thumbnail
        if (DefineImageType(sThumbnailImagePath) == ImageFormat.Gif)
        {
            using (oThumbnail)
            {
                ImageManipulation.OctreeQuantizer quantizer = new ImageManipulation.OctreeQuantizer(255, 8 );
               
                using (Bitmap bmpQuantized = quantizer.Quantize(oThumbnail))
                {
                    bmpQuantized.Save(sThumbnailImagePath, ImageFormat.Gif);
                }
            }
        }
        else
        {           
            ImageCodecInfo[] iciInfo = ImageCodecInfo.GetImageEncoders();
            EncoderParameters encoderParameters;
            encoderParameters = new EncoderParameters(1);
            encoderParameters.Param[0] = new EncoderParameter(Encoder.Quality, 100L);

            oThumbnail.Save(sThumbnailImagePath, iciInfo[1], encoderParameters);
        }

        if (oThumbnail != null) { oThumbnail.Dispose(); }
    }

public static ImageFormat DefineImageType(string sFileName)
    {
        string sFileExtention = Path.GetExtension(sFileName);
        ImageFormat oImageFormatToReturn;

        switch (sFileExtention)
        {
            case ".gif":
                oImageFormatToReturn = ImageFormat.Gif;
                break;
            case ".png":
                oImageFormatToReturn = ImageFormat.Png;
                break;
            case ".bmp":
                //oImageFormatToReturn = ImageFormat.Bmp;
                //break;
            case ".jpg":
            case ".jpeg":
            case ".jpe":
            default:
                oImageFormatToReturn = ImageFormat.Jpeg;
                break;

        }

        return oImageFormatToReturn;
    }

Since there is a problem with creating thumbnails from GIF images the function uses a class ImageManipulation.OctreeQuantizer. You can get the source code for this class from this MSDN article “Optimizing Color Quantization for ASP.NET Images” written by Morgan Skinner. You can download the project DotNET_Color_Quantization_Code.msi, build it and use the ImageManipulation.dll in your project. Of course the animated GIFs will not be animated anymore, but at least the transparency is preserved.

You can use the function with this sample code:

GenerateImageThumbnail(filePhoto.PostedFile.InputStream,"c:\your_thumbnaill_file_name.jpg", 400, 400);

, , ,
Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • del.icio.us
  • dzone
  • Netscape
  • digg
  • YahooMyWeb
  • Technorati

Overview

The Web Client Software Factory provides an integrated set of guidance that assists architects and developers in creating composite Web client applications. The application blocks, software factory includes reference implementation, how tos, patterns, and Visual Studio .NET extensions.

System Requirements

Supported Operating Systems: Windows Server 2003; Windows XP

Microsoft .NET Framework 2.0
Microsoft .NET Framework 3.0
Visual Studio 2005 extensions for .NET Framework 3.0 (Windows Workflow Foundation)

In the Box

  • Application Blocks and Libraries
  • Visual Studio 2005 extensions for automating common tasks. Guidance Automation Overview
  • How-to topics and QuickStarts
  • Architecture guidance and Patterns for Web Client Applications
  • Reference Implementation (a sample applications using the Factory)
  • Training content (Hands-On-Labs, demos, etc) (under development)

Download Page 
Community site

,
Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • del.icio.us
  • dzone
  • Netscape
  • digg
  • YahooMyWeb
  • Technorati

Using JavaScript to prevent email addresses harvesting by spammers if an effective method against the standard harvesting programs. Nevertheless the spammers could modify their harvesting programs to read the email addresses from the JavaScript. That is why this is not a bulletproof solution but is really effective and could easily be customized for any web site.
 
The idea is to create a JavaScript function that will print the email address:

function printEmail(theName, theExtras, theLink, theDomain) {

var theEmail = theName + "@" + theDomain;

    if (theName == "") {
        theName = "ERROR";
        theLink = "ERROR";
        myEmail = theName;
        myLink = theLink;
       
    } else {
   
        if ((theExtras == "") && (theLink =="")){
            myEmail = theEmail;
            myLink = theEmail;
        }
       
        if ((theLink == "") && (theExtras != "")){
            myLink = theEmail;
            myEmail = theEmail+theExtras;
        }
       
        if ((theLink != "") && (theExtras != "")){
            myLink = theLink;
            myEmail = theEmail+theExtras;
        }
       
        if ((theLink != "") && (theExtras == "")){
            myLink = theLink;
            myEmail = theEmail;
        }
    }
   
    document.write(’<a href="mailto:’ + myEmail + ‘" class="email">’ + myLink + ‘</a>’);
}

You can call the function using this line of code:

<script type="text/javascript">printEmail("ivan", "", "", "gmail.com");</script>

,
Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • del.icio.us
  • dzone
  • Netscape
  • digg
  • YahooMyWeb
  • Technorati

This Word Press Plugin adds del.icio.us Play Tagger into your blog. Play Tagger is a neat little tool that allows you to easily play mp3 files on your website or blog. It will add a player tool to all the mp3 links on the page.

Example mp3 link

Installation Instructions

Just drop the delicious-play-tagger.php file into your wp-content/plugins folder and activate the plugin in the admin. The plugin will then add the necessary code at the right position in the HTML of your blog’s pages.

Download ver 1.0

, , ,
Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • del.icio.us
  • dzone
  • Netscape
  • digg
  • YahooMyWeb
  • Technorati

This Word Press Plugin adds del.icio.us Tagometer Badge into your blog. The badge can be added in the home page, in the side bar or after each post or page.

Installation Instructions

Just drop the delicious-tagometer-badge.php file into your wp-content/plugins folder and activate the plugin in the admin. Go to the “del.icio.us Tagometer” options page under “Options” and set the type of Tagometer  Badge that you want to use.

The plugin will then add the necessary code at the right position in the HTML of your blog’s pages

Upgrading

Just replace delicious-tagometer-badge.php file into your wp-content/plugins folder and change the Options of the plug-in.

Download ver 1.1

, , ,
Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • del.icio.us
  • dzone
  • Netscape
  • digg
  • YahooMyWeb
  • Technorati

Have you ever been in a situation when you want to set the next value of the identity column? This is s simple task that can be done with DBCC CHECKIDENT statement. This example deleted all records with ID greater than 135 from the table Products. Than it sets the current identity value to 135. Thus when the next record is added it will have ID with value 136.

DELETE  FROM [Products] WHERE id>135
GO

DBCC CHECKIDENT (Products, RESEED, 135)
GO

, , ,
Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • del.icio.us
  • dzone
  • Netscape
  • digg
  • YahooMyWeb
  • Technorati

Microformats

“Designed for humans first and machines second, microformats are a set of simple, open data formats built upon existing and widely adopted standards. Instead of throwing away what works today, microformats intend to solve simpler problems first by adapting to current behaviors and usage patterns (e.g. XHTML, blogging).” Source: http://microformats.org/about/

I really like microformats because they allow machines to export data like contacts in vCard format with a simple change of existing code. With a few simple CSS class additions I’ve created a web site that supports microformats.

More information how to use microformats can be found on the official web page: http://microformats.org/. The site includes hCard, hCalendar and hReview creators that will show you how the microformats are embedded in XHTML for example.

This is a simple example of HTML with added microformats hCard:

<div class="vcard">
     <a class="url fn" href="http://www.ivanuzunov.net/">Ivan Uzunov</a>
     <div class="org">Uzunov Ltd.</div>
     <a class="email" href="mailto:myemail@uzunov.com">myemail@uzunov.com</a>
</div>

To take advantage from microformats as a simple website user you will need a tool that extracts the data from the web site page and allows you to do something with it. For example it can import contacts data into your email client. I’m using these two Firefox extensions:

  1. Tails Export (https://addons.mozilla.org/firefox/2240/)
     
    I prefer this one but is not supported in Firefox 2.0 yet.
     
  2. Operator (https://addons.mozilla.org/firefox/4106/)

Of course the microformats could be dangerous because of spammers. They could easily collect email addresses.

, , , , ,
Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • del.icio.us
  • dzone
  • Netscape
  • digg
  • YahooMyWeb
  • Technorati

The contains(t) function returns true if the string contains the value of the parameter "t" and false if it doesn’t. To extend the String.prototype with the contains(t) function I use this line of code:

String.prototype.contains = function(t) { return this.indexOf(t) >= 0 ? true : false }

This is sample code how to use the contains(t) function:

var sMyVar = new String (" testing text ");
alert(sMyVar.contains(’testing’));
 
//use it with the value of a text box
document.getElementById("txtMyTextBox").value.contains(’some text’);

, ,
Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • del.icio.us
  • dzone
  • Netscape
  • digg
  • YahooMyWeb
  • Technorati

« Prev - Next »