Tuesday 1 May 2012

Popup Window in Asp.net

Popup Window  Model
Step 1: Open visual studio->new website ->add new item-> web form

Add two link buttons from toolbox to web form  and add code to source page as given below:

Default.aspx


<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script>

        var winheight = 100
        var winsize = 100
        var x = 5
        function openwindow(thelocation) {
            temploc = thelocation
            if (!(window.resizeTo && document.all) && !(window.resizeTo && document.getElementById)) {
                window.open(thelocation)
                return
            }
            win2 = window.open("", "", "scrollbars")
            win2.moveTo(0, 0)
            win2.resizeTo(100, 100)
            go2()
        }
        function go2() {
            if (winheight >= screen.availHeight - 3)
                x = 0
            win2.resizeBy(5, x)
            winheight += 5
            winsize += 5
            if (winsize >= screen.width - 5) {
                win2.location = temploc
                winheight = 100
                winsize = 100
                x = 5
                return
            }
            setTimeout("go2()", 50)
        }
</script>

<script language="JavaScript">
    function expandingWindow(website) {
        var windowprops = 'width=100,height=100,scrollbars=yes,status=yes,resizable=yes'
        var heightspeed = 2; // vertical scrolling speed (higher = slower)
        var widthspeed = 7;  // horizontal scrolling speed (higher = slower)
        var leftdist = 10;    // distance to left edge of window
        var topdist = 10;     // distance to top edge of window

        if (window.resizeTo && navigator.userAgent.indexOf("Opera") == -1) {
            var winwidth = window.screen.availWidth - leftdist;
            var winheight = window.screen.availHeight - topdist;
            var sizer = window.open("", "", "left=" + leftdist + ",top=" + topdist + "," + windowprops);
            for (sizeheight = 1; sizeheight < winheight; sizeheight += heightspeed)
                sizer.resizeTo("1", sizeheight);
            for (sizewidth = 1; sizewidth < winwidth; sizewidth += widthspeed)
                sizer.resizeTo(sizewidth, sizeheight);
            sizer.location = website;
        }
        else
            window.open(website, 'mywindow');
    }

</script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <a href="javascript:openwindow('http://www.AryabhattaSolution.com')">link1</a>
    <br />
    <a href="#" onClick="expandingWindow('http://www.c-sharpcorner.com');return false">link2</a>
    </div>
    </form>
</body>
</html>

Run the application 
Click link1 to see Horizontal window popup
Click link2 to see Vertical Window popup

No comments:

Post a Comment