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

October 5th, 2009, 05:55 AM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Location: Tehran, Iran
Posts: 922
Thanks: 0
Thanked 1 Time in 1 Post
|
|
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 
|

October 5th, 2009, 09:29 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Location: Exeter, , United Kingdom.
Posts: 2,922
Thanks: 0
Thanked 13 Times in 12 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.
__________________
--
Joe
|

October 5th, 2009, 03:01 PM
|
|
Friend of Wrox
|
|
Join Date: Jun 2007
Location: San Diego, CA, USA.
Posts: 278
Thanks: 0
Thanked 4 Times in 4 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.
|

October 6th, 2009, 01:49 PM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Location: Tehran, Iran
Posts: 922
Thanks: 0
Thanked 1 Time in 1 Post
|
|
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.
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
 |