home hardware prices news articles forums photos user reviews
Go Back   Tech Support Forums - TechIMO.com > PC Hardware and Tech > Webmastering and Programming
Ask a Tech Support Question (free)!

Prevent multiple postbacks JS/.NET

Reply
Get bargains at  »  Dealighted.com
 
Thread Tools Search this Thread
Currently Active Users: 1805
Discussions: 200,950, Posts: 2,379,448, Members: 246,312
Old June 24th, 2008, 03:47 PM   Digg it!   #1 (permalink)
Junior Member
 
Join Date: Dec 2007
Posts: 20
Prevent multiple postbacks JS/.NET

I've seen many people ask, and today had to figure out a solution myself. Essentially you have a div and nested div. The container ends up being the width and height of the page, layered on top of all other page elements effectively disabling them. The inner div can display a message of some type.

JS CODE
Code:
<script language="javascript" type="text/javascript">
//.NET Code:
        //Page.ClientScript.RegisterOnSubmitStatement(this.GetType(), "onSubmitFunction", "jsOnSubmit();");
        function jsOnSubmit(){
            //If this page has validation controls, make sure the page is valid.    
            if ( typeof( window[ 'Page_IsValid' ] ) != "undefined" ) {
                if(Page_IsValid == true){
                    doDiv();
                }
            }
            //Otherwise, disable page / display msg
            else {
                doDiv();
            }
        }           
        //Disable all controls via transparent div, display msg
        function doDiv(){
            //get the background and msg box <DIV>s
            _backgroundElement = document.getElementById('<%= _backgroundElement.ClientID %>');
            _backgroundElementMsgBox = document.getElementById('<%= _backgroundElementMsgBox.ClientID %>');

            //initiaze fail-safe heights
            var windowWidth = 100;
            var windowHeight = 100;
            var msgPos = 200;
    
            //Set window width and height
            //Works for all web 2.0 browsers
            if(typeof(window.innerWidth) == 'number'){
                //FireFox
                windowWidth = window.innerWidth;
                windowHeight = window.innerHeight;
            } else if( document.documentElement && document.documentElement.clientHeight) {
                //IE
                windowWidth = document.documentElement.clientWidth;
                windowHeight = document.documentElement.clientHeight;
            } else if( document.body && document.body.clientHeight){
                //Linux Distros
                windowWidth = document.body.clientWidth;
                windowHeight = document.body.clientHeight;
            }
            
            //Set width of the transparent div
            _backgroundElement.style.width = Math.max(Math.max(document.documentElement.scrollWidth, document.body.scrollWidth), windowWidth)+'px';
            _backgroundElement.style.height = Math.max(Math.max(document.documentElement.scrollHeight, document.body.scrollHeight), windowHeight)+'px';
            
            //Set position of the inner msg div
            _backgroundElementMsgBox.style.top = msgPos + 'px';
            _backgroundElementMsgBox.style.left = ((windowWidth - 250) / 2) + 'px';

            //Make divs visible, posts back
            _backgroundElement.style.display = 'block';
            _backgroundElementMsgBox.style.display = 'block';
            
            //For IE: make the GIF animated
            setTimeout('document.images["<%= loader.ClientID %>"].src = "./images/loader.gif"', 200); 
        }    </script>
ASP Front-Side
Code:
<div id="_backgroundElement" runat="server" style="text-align: center; display: none; position: absolute; left: 0px; top: 0px; z-index: 9999; background-color: #cccccc; opacity:.00; filter: alpha(opacity=00); -moz-opacity: 0.0;"></div>
<div id="_backgroundElementMsgBox" runat="server" style="display: none; position: absolute; padding: 10px 5px 5px 5px; text-align: center; border: 1px solid #bb0000; background-color: #ffffff; z-index: 10000; font-weight: bold; width: 250px; height: 75px; top: 0px; left: 0px;">
    <asp:Image ID="loader" runat="server" ImageUrl="~/images/loader.gif" /><br /><br />
    Saving Survey Progress
</div>
ASP Code Behind
Code:
protected void Page_Load(object sender, EventArgs e)
        {
            Page.ClientScript.RegisterOnSubmitStatement(this.GetType(), "onSubmitFunction", "jsOnSubmit();");
        }
I got the loader from: Ajaxload - Ajax loading gif generator
For opacity support: Mandarin Design: CSS Opacity and Transparency

edit: updated code so loader displays correct in IE as well as FF.
edit: broke nested div out, so we could retain full opacity for the msg box


-b
"reluctantly coding asp since 2008"
Attached Images
 

Last edited by new_guy217 : June 24th, 2008 at 04:36 PM.
new_guy217 is offline   Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search

Similar Threads
Thread Thread Starter Forum Replies Last Post
multiple versions of .NET framework Good Companion Applications and Operating Systems 4 July 14th, 2007 02:06 AM
Multiple Graphics cards and multiple monitors too, radeon 9250's madadamuk Graphics Cards and Displays 9 February 12th, 2006 04:55 PM
multiple boot/multiple partition question butch81385 Applications and Operating Systems 13 January 20th, 2005 06:30 PM
Multiple Monitors w/ multiple WMs originel Linux and Unix 3 September 13th, 2003 05:00 AM
Anyone able to get multiple users on battle.net behind one router? newbie~wan General Gaming Discussion 15 January 5th, 2002 12:24 PM


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Most Active Discussions
The disrespect of Obama by Russian .. (35)
Making Health Care Worse (177)
Wireless Televisions. (12)
windows 7 problem (7)
CPU fan stops spinning randomly (8)
Regular Build (7)
radeon x850xt platinum & shader.. (6)
Is the PSU I received dead? (12)
Print spooler problem (15)
windows vista security holes (10)
HIS HD5770 graphic card question (15)
Install XP pro and a Vista laptop ?.. (11)
Dept. of HS: NSA 'Helped' Develop V.. (15)
Foreign voltage (10)
Recent Discussions
windows vista security holes (10)
EVGA 9800 gtx help with finding a goo.. (9)
Internet Lost (2)
Point and Shoot Camera Suggestions. (4)
Regular Build (7)
Multiple Restarts Required at Boot (2)
Ideal cheap graph card for PC-Gaming? (18)
radeon x850xt platinum & shader 3 (6)
Graphics Card Upgrade Question (4)
For Sale BFG GTX285 OC2 with 10 year .. (3)
How to convert MP3's (4)
Wireless Televisions. (12)
Laptop with wireless problem. (2)
Hp Artist Edition + Matching Bag (0)
My monitor won't turn on after instal.. (0)
Asus P4G8X Mobo (6)
Xbox 360 GTA: SA disk error (1)
Is the PSU I received dead? (12)
windows 7 internet problem (5)
BSOD On Startup (ntoskrnl.exe) (2)
Print spooler problem (15)
Have you switched yet? (86)
screen resolution vs monitor size (2)
sms storage to PC (0)
Open With ..... Win7 (0)


All times are GMT -4. The time now is 12:30 AM.
TechIMO Copyright 2009 All Enthusiast, Inc.



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28