Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
SamC
White Water Yakist
3467 Posts |
Posted - 2006-04-07 : 15:55:55
|
Server side, I can test for postback or initial page load.Is there a way to test in JavaScript that a page is being rendered after a postback?Sam |
|
robvolk
Most Valuable Yak
15732 Posts |
Posted - 2006-04-07 : 16:50:20
|
Create a hidden control that writes a value only on initial load, and have the JS check that control's value. I've done this in regular ASP, it's just as easy in .Net. |
|
|
DustinMichaels
Constraint Violating Yak Guru
464 Posts |
Posted - 2006-04-07 : 18:36:32
|
You could check the referrer url in JavaScript.if(document.referrer == document.location){ //the page posted back.}else{ //the page is loading for the first time.}The only problem with this is that you can install some security programs that can supress the referrer. You should probably do what robvolk recommended. |
|
|
SamC
White Water Yakist
3467 Posts |
Posted - 2006-04-07 : 22:12:24
|
Rob's suggestion is great. Simple too.Sam |
|
|
SamC
White Water Yakist
3467 Posts |
Posted - 2006-04-07 : 22:24:05
|
One problem... I read somewhere that <body onload= may fire before the page is completely loaded. Is this a real problem? Is there a better way to execute a script after a page is fully loaded?This isn't elegant, but I could make it the last line...<script type="text/javascript">window.onload="DoPostBackStuff(<%=Request.ServerVariables("REQUEST_METHOD")%>=='POST');"</script></body>Better method?Not legal, but if JavaScript events could be added to a closing element:</body onload="myJavaScript();"> |
|
|
DustinMichaels
Constraint Violating Yak Guru
464 Posts |
Posted - 2006-04-07 : 23:44:11
|
Put this an in external javascript file or in your <script> block.if(document.getElementById) window.onload = load;function load(){ put your on load stuff here.} |
|
|
Kristen
Test
22859 Posts |
Posted - 2006-04-08 : 01:16:24
|
"This isn't elegant, but I could make it the last line..."I believe that OnLoad is supposed to run after the images are downloaded and everything is rendered ... whereas I expect a script "as the last line" will execute when it is encountered - but that might suit your needs of course!Kristen |
|
|
afrika
Master Smack Fu Yak Hacker
2706 Posts |
Posted - 2006-04-08 : 02:43:32
|
This though is not a java script code, but a server side asp code that makes sure the browser does not cache the page. Though it does not work well in earlier versions of mozilla, this way you can make sure your page is not a postback.Hope this helps <% Response.CacheControl = "no-cache" %><% Response.AddHeader "Pragma", "no-cache" %><% Response.Expires = -1 %><%response.ExpiresAbsolute=#7/5/1980 00:00:00#%> |
|
|
|
|
|