p2p.wrox.com Forums

Need to download code?

View our list of code downloads.


Go Back   p2p.wrox.com Forums > Web Programming > JavaScript > Javascript
I forgot my password Register Now
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Javascript General Javascript discussions.

Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript section of the Wrox p2p Programmer to Programmer discussion community. This is a community of more than 40,000 computer programmers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining our free Wrox p2p community you can post your own programming questions and respond to other programmers’ questions. Registered users also don't have to see the ads that are displayed to guests. Registration is fast, simple and absolutely free so please, join today!
Join today and post to win prizes! Post more to increase your chances of being Wrox’s top poster of the month.

Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old October 5th, 2009, 05:55 AM
Friend of Wrox
Points: 3,152, Level: 23
Points: 3,152, Level: 23 Points: 3,152, Level: 23 Points: 3,152, Level: 23
Activity: 20%
Activity: 20% Activity: 20% Activity: 20%
 
Join Date: Jun 2003
Location: Tehran, Iran
Posts: 922
Thanks: 0
Thanked 1 Time in 1 Post
Send a message via Yahoo to melvik
Default function to fire only once in Pageload

hello there
I have a function like below
Code:
        
function InisialText() 
{
            document.getElementById('TBoxEmpCnt').value = 0;
}
& I only what this to fire only once in pageLoad as I set it in
Code:
<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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #2 (permalink)  
Old October 5th, 2009, 09:29 AM
joefawcett's Avatar
Wrox Author
Points: 8,994, Level: 40
Points: 8,994, Level: 40 Points: 8,994, Level: 40 Points: 8,994, Level: 40
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Exeter, , United Kingdom.
Posts: 2,922
Thanks: 0
Thanked 13 Times in 12 Posts
Default

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.
__________________
--

Joe
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #3 (permalink)  
Old October 5th, 2009, 03:01 PM
Friend of Wrox
Points: 941, Level: 11
Points: 941, Level: 11 Points: 941, Level: 11 Points: 941, Level: 11
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2007
Location: San Diego, CA, USA.
Posts: 278
Thanks: 0
Thanked 4 Times in 4 Posts
Default

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.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #4 (permalink)  
Old October 6th, 2009, 01:49 PM
Friend of Wrox
Points: 3,152, Level: 23
Points: 3,152, Level: 23 Points: 3,152, Level: 23 Points: 3,152, Level: 23
Activity: 20%
Activity: 20% Activity: 20% Activity: 20%
 
Join Date: Jun 2003
Location: Tehran, Iran
Posts: 922
Thanks: 0
Thanked 1 Time in 1 Post
Send a message via Yahoo to melvik
Default

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
__________________
Always[:)],
Hovik Melkomian.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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

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

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to fire an Event ackid32 BOOK: Visual Basic 2005 Programmer's Reference 5 October 7th, 2009 07:54 PM
Problem with accessing function in pageload method nelly78 .NET Framework 2.0 5 September 8th, 2008 07:49 AM
pageload is not correct... pc_35 ASP.NET 1.0 and 1.1 Basics 5 September 26th, 2006 10: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 11:20 PM



All times are GMT -4. The time now is 08:20 AM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
© 2008 Wiley Publishing, Inc