Showing posts with label html. Show all posts
Showing posts with label html. Show all posts

Wednesday, February 27, 2013

How to make thumbnail of an image and fix this in center position of div using asp.net and c#

First you have to create a page of CreateThumbnail.aspx and paste this below code :-
    protected void Page_Load(object sender, EventArgs e)
    {
        string Image = Request.QueryString["Image"];

        if (Image == null)
        {
            this.ErrorResult();
            return;
        }

        string sSize = Request["Size"];
        int Size = 120;
        if (sSize != null)
            Size = Int32.Parse(sSize);

        string Path = Server.MapPath(Request.ApplicationPath) + "\\" + Image;
        Bitmap bmp = CreateThumbnail(Path, Size, Size);

        if (bmp == null)
        {
            this.ErrorResult();
            return;
        }

        string OutputFilename = null;
        OutputFilename = Request.QueryString["OutputFilename"];

        if (OutputFilename != null)
        {
            if (this.User.Identity.Name == "")
            {
                // *** Custom error display here
                bmp.Dispose();
                this.ErrorResult();
            }

            try
            {
                bmp.Save(OutputFilename);
            }

            catch (Exception ex)
            {
                bmp.Dispose();
                this.ErrorResult();
                return;
            }
        }

        // Put user code to initialize the page here
        Response.ContentType = "image/jpeg";
        bmp.Save(Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg);
        bmp.Dispose();
    }

    private void ErrorResult()
    {
        Response.Clear();
        Response.StatusCode = 404;
        Response.End();
    }

    public static Bitmap CreateThumbnail(string lcFilename, int lnWidth, int lnHeight)
    {
        System.Drawing.Bitmap bmpOut = null;
        try
        {
            Bitmap loBMP = new Bitmap(lcFilename);
            ImageFormat loFormat = loBMP.RawFormat;

            decimal lnRatio;
            int lnNewWidth = 0;
            int lnNewHeight = 0;

            //*** If the image is smaller than a thumbnail just return it
            if (loBMP.Width < lnWidth && loBMP.Height < lnHeight)
                return loBMP;

            if (loBMP.Width > loBMP.Height)
            {
                lnRatio = (decimal)lnWidth / loBMP.Width;
                lnNewWidth = lnWidth;
                decimal lnTemp = loBMP.Height * lnRatio;
                lnNewHeight = (int)lnTemp;
            }
            else
            {
                lnRatio = (decimal)lnHeight / loBMP.Height;
                lnNewHeight = lnHeight;
                decimal lnTemp = loBMP.Width * lnRatio;
                lnNewWidth = (int)lnTemp;
            }

            // System.Drawing.Image imgOut = loBMP.GetThumbnailImage(lnNewWidth,lnNewHeight, null,IntPtr.Zero);

            // *** This code creates cleaner (though bigger) thumbnails and properly
            // *** and handles GIF files better by generating a white background for
            // *** transparent images (as opposed to black)
            bmpOut = new Bitmap(lnNewWidth, lnNewHeight);
            Graphics g = Graphics.FromImage(bmpOut);
            g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
            g.FillRectangle(Brushes.White, 0, 0, lnNewWidth, lnNewHeight);
            g.DrawImage(loBMP, 0, 0, lnNewWidth, lnNewHeight);

            loBMP.Dispose();
        }
        catch
        {
            return null;
        }
        return bmpOut;
    }
How to call this page on demo page :-
Add this script to set image in center position of div :-
      
      

Monday, December 10, 2012

How to get query string value using javascript

String.prototype.GetQSValue = function() {
    if (!arguments[0]) return null;
    var strFL = unescape(this)
    var regEx = new RegExp("[?&]" + arguments[0] + "=.*$", "g");
    var strMatch = strFL.match(regEx);
    if (strMatch == null) return null
    var arrParts = strMatch.toString().split("&");
    return (arrParts[0].length == 0) ? arrParts[1].split("=")[1] : arrParts[0].split("=")[1];
}
How to call this function, you can see this in bottom. I am getting here "return" parameter's value.
var strLink = window.location.search;
var returnurl = strLink.GetQSValue('return');

Saturday, October 20, 2012

How to allow only Numeric values in input textbox using jQuery

$(document).ready(function() {
    $("#txtPrice").keydown(function(event) {
        // Allow: backspace, delete, tab, escape, and enter
        if ( event.keyCode == 46 || event.keyCode == 8 || event.keyCode == 9 || event.keyCode == 27 || event.keyCode == 13 || 
             // Allow: Ctrl+A
            (event.keyCode == 65 && event.ctrlKey === true) || 
             // Allow: home, end, left, right
            (event.keyCode >= 35 && event.keyCode <= 39)) {
                 // let it happen, don't do anything
                 return;
        }
        else {
            // Ensure that it is a number and stop the keypress
            if (event.shiftKey || (event.keyCode < 48 || event.keyCode > 57) && (event.keyCode < 96 || event.keyCode > 105 )) {
                event.preventDefault(); 
            }   
        }
    });
});

Wednesday, October 17, 2012

What is difference between the GET and POST methods?

  1. In GET Method, All the name value pairs are submitted as a query string in URL. But in the POST method name value pairs are submitted in the Message Body of the request. 
  2. GET Method is not secured as it is visible in plain text format in the Location bar of the web browser. But POST Method is secured because Name-Value pairs cannot be seen in location bar of the web browser. 
  3. Also in GET method characters were restricted only to 256 characters. But in the case of POST method characters were not restricted. 
  4. About form default, Get is the defualt method for any form, if you need to use the post method, you have to change the value of the attribute "method" to be Post.  
  5. About the data type that can be send, with Get method you can only use text as it sent as a string appended with the URL, but with post is can text or binary. 
  6. If get method is used and if the page is refreshed it would not prompt before the request is submitted again. And if post method is used and if the page is refreshed it would prompt before the request is resubmitted. 
  7. GET method can be bookmarked. But POST method can not be bookmarked.
  8. In GET method data is always submitted in the form of text. In POST method data is submitted in the form as specified in enctype attribute of form tag and thus files can be used in FileUpload input box.
  9. GET method should not be used when sending passwords or other sensitive information. POST method used when sending passwords or other sensitive information.
  10. GET method can be cached. POST method can not cached.

Thursday, October 8, 2009

How can I get my menu to display over my Flash (.swf) movie?

<object height="200" width="780">
<param name="wmode" value="transparent">
<param name="movie" value="Slide1/SlideShow.swf">
<param name="quality" value="high">
<embed src="Slide1/SlideShow.swf" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" wmode="transparent" type="application/x-shockwave-flash" height="200" width="780"/>
</object>