Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript
Javascript General Javascript discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old October 5th, 2009, 04:55 AM
Friend of Wrox
Join Date: Jun 2003
Posts: 996
Thanks: 2
Thanked 11 Times in 11 Posts
Send a message via Yahoo to melvik
Default function to fire only once in Pageload

hello there
I have a function like below
function InisialText() 
            document.getElementById('TBoxEmpCnt').value = 0;
& I only what this to fire only once in pageLoad as I set it in
<body onload="InisialText();">
but since its in an ASP.NET 2 page it fires again & again in any button click (ASP.NET Buttons)

I can handle it with ASP in Code Behind Page
but there anyway to handle it with JavaScript? like a global valiable & set it to falae & ....
its a long time I havent worked with JS

Tnx in advance
Old October 5th, 2009, 08:29 AM
joefawcett's Avatar
Wrox Author
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts

If you initiate a server-side event then the page will be fetched anew from the server. You could use a cookie to set the fact that the function had been called already or use the server-side onload function to set a client-side variable appropriately only if it wasn't a postback.
Old October 5th, 2009, 02:01 PM
Friend of Wrox
Join Date: Jun 2007
Posts: 477
Thanks: 10
Thanked 19 Times in 18 Posts

Correct me if I'm wrong, but it sounds like you're trying to persist data in the text box so that users don't have to retype information if they click a button that triggers a post back or if they accidentally wander off the page etc.

In this case, is it necessary to set the text box to anything? I would suggest that an empty textbox is the best way to go. If you're setting it to 0 because the information is going into a DB field that doesn't allow nulls (a very good practice), I suggest allowing people to leave it blank and handle the problem when they submit the form. Rather than setting the textbox to 0 (which someone might delete anyway, causing validation problems) simply purify any response the user sends back. Check to see if text value of a field includes anything unacceptable and replace it with the default value you want, like swapping "" for "0" or whatever. But I think you'll have fewer problems handling this with validation than on the front end.

Whatever you can do or dream you can, begin it. Boldness has genius, power and magic in it. Begin it now.
-Johann von Goethe

When Two Hearts Race... Both Win.
-Dove Chocolate Wrapper

Chroniclemaster1, Founder of www.EarthChronicle.com
A Growing History of our Planet, by our Planet, for our Planet.
Old October 6th, 2009, 12:49 PM
Friend of Wrox
Join Date: Jun 2003
Posts: 996
Thanks: 2
Thanked 11 Times in 11 Posts
Send a message via Yahoo to melvik

Dear Joe & Chroniclemaster1:
tnx for ur comments, Im done my problem using a hidden html input (textbox) & making it a serverSide so I had access both side easily.
the rest is like what Chroniclemaster1 said
& Joe u were right about page roloading & ... so it was supied to do it only in JavaScript

Tnx again for ur help & time
Hovik Melkomian.

Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem with accessing function in pageload method nelly78 .NET Framework 2.0 5 September 8th, 2008 06:49 AM
pageload is not correct... pc_35 ASP.NET 1.0 and 1.1 Basics 5 September 26th, 2006 09:20 AM
Help My house on Fire Matthew Access VBA 9 November 30th, 2005 03:21 PM
Overrinding PageLoad help! Bobafett ASP.NET 1.0 and 1.1 Basics 6 September 7th, 2004 10:20 PM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.