home hardware prices news articles forums photos user reviews
Go Back   Tech Support Forums - TechIMO.com > PC Hardware and Tech > Webmastering and Programming
Join TechIMO for Free!
Register Blogs FAQ Members List Calendar Search Today's Posts Mark Forums Read
Reply Get bargains at  »  Dealighted.com
 
Thread Tools
Currently Active Users: 2677
Discussions: 186,606, Posts: 2,227,047, Members: 230,241
Free Scan: Update Your PC's Outdated Drivers to Optimize Performance
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
TechIMO.com Ads - Login or register for less ads.
How many errors does your computer have?

You no longer need to guess! This free stability scan and registry cleaner download will give you a complete diagnosis of your Windows registry, identifying errors and conflicts.

FREE instant scan


Guest, Register Free! to remove this ad and get your tech support questions answered in minutes!
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may post new threads
You may post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

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

Most Active Discussions
Is It Just Me? (528)
Misery Loves Company... (1849)
Why Does the MOON Grow Bigger as It.. (18)
heatsink issue (10)
New Mobo (18)
UPGRADING C/D DRIVE TO 250GB & .. (14)
SSD's, RAID, and External Backup (7)
1 internet. 1 house. 3 computer. ho.. (13)
Is This A Compatible Gaming PC? (18)
Recent Discussions
system restore 'next' button wo.. (1)
firewall (1)
C++ compiler suggestions (4)
Official World of Warcraft Thre.. (4529)
Programming question (2)
UPGRADING C/D DRIVE TO 250GB &a.. (14)
Ubuntu or Xubuntu....anyone!!? (7)
Building my first PC and need s.. (0)
PNY vs Gainward (3)
FS: Dell 6000 laptop, modded 36.. (2)
Apple iPod touch 16 GB $200 (4)
Six 28-Disc Cross Design Black .. (4)


All times are GMT -4. The time now is 11:57 AM.
TechIMO Copyright 2008 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