Refresh ASP Page

In an ASP page I am traping a onchange event on input box and  calling a VBScript function for this event.

here I am setting a Hidden box value to '1'.

In the asp I am geting this hidden box value by request.form and if it is '1',  I am using a function of my own com object. It is working fine.

I am using VBscript at the end of the ASP to reset it to '0'

But after this If I press Refresh / F5 button the hidden box value is still '1'. So calling the com funtion again.

I want to call the function only onchange event and not on refresh. ASP gives hidden box value as "" on first launch and on refresh it gives '1'.

Is there any function in ASP that runs while the user presses the Refresh/F5 button?

Regards.
Viswanath.
viswanathatAsked:
Who is Participating?
 
HooliganConnect With a Mentor Commented:
not sure im clear on the problem, but if i am reading it right, why dont you just set the value of the hidden field back to whatever value it needs to be at the end of your onChange event function?
0
 
appariCommented:
as far as i know there is no  function in ASP that runs while the user presses the Refresh/F5 button.

anyway you are setting the hidden variable to 1 on change event, always  assign "" from asp page instead of assigning 1 on refresh. that should work.



0
 
viswanathatAuthor Commented:
Dear appari

   Tanx..  

i have to call a com function onchange event only.
for this i am using a hidden box and changing the value on change

on first launch the value doesn't mactch and the function  is not called .. it's ok

onchange the value changes and the function is called. it's ok.

on refresh button click the request.form returns the same value in the input box even though i reset it.

how can i set a ASP variable from a event based vbscript?
so that i can call the COM function on this event only?

or how to call COM function from event based script?

Regards.
Viswanath.

0
What Kind of Coding Program is Right for You?

There are many ways to learn to code these days. From coding bootcamps like Flatiron School to online courses to totally free beginner resources. The best way to learn to code depends on many factors, but the most important one is you. See what course is best for you.

 
gingiGuyCommented:
You could use cookies to record the number of times the user has visited the page, and extraploate from that if they pressed refresh.
The same could be acheived with session variables.

in session_onstart() (in the global asa), you could create a variable

session("IsFirstTime") = true

Then when the user reaches your pages you can test for the value of this variable, then do

session("IsFirstTime") = false

so that if the pages is called again (ie refereshed) it would not execute that code inside your testing block

Hope this is of some help, or that you can get some other ideas from this.

Guy
0
 
appariCommented:
can u post your function you were calling onchange event.
0
 
appariCommented:
can u post code of your function you were calling onchange event.
0
 
brunoCommented:
you would have to do something on the body onload event to check what the value was....
0
 
viswanathatAuthor Commented:
it is like this : Here the com function is called again in refresh after first onchange. how to prevent this..?
copy this to a .asp file and pls check.

one simple solution is to call another asp onchange to call the com function and return to this asp. Then any parent asp refresh does not call the com function but it does simple refresh.

Regards.
Viswanath.

<HTML>                    
<body>
<form name = "Form1" method="post"  action="test.asp">

<%  Response.write "Change and press tab : <input type= text name= Curval  OnChange= ""onenter(  this.value );"" value = "  & 5 & "><BR>"

Response.write  "<INPUT TYPE=text name = EnterPressedHidden  value = " & Request.Form("EnterPressedHidden")&"> "

Response.write   Request.Form("EnterPressedHidden")
if(Request.Form("EnterPressedHidden") = 1) then
     Response.Write "Call COM function here only onchange"
end if  
%>

<SCRIPT LANGUAGE=VBScript >      ' reset the value to zero.
document.Form1.EnterPressedHidden.value = 0    
</SCRIPT>

</FORM>

<SCRIPT LANGUAGE=VBScript   > 
function onenter(val)
     document.Form1.EnterPressedHidden.value = 1
     document.Form1.submit()       'calls same asp
end function
</SCRIPT>
</body>
</HTML>

0
 
appariCommented:
try this

remove this
<SCRIPT LANGUAGE=VBScript >      ' reset the value to zero.
document.Form1.EnterPressedHidden.value = 0    
</SCRIPT>

change this line to
Response.write  "<INPUT TYPE=text name = EnterPressedHidden  value = ''> "
0
 
viswanathatAuthor Commented:
dear appari

if you write Response.write it will creat another text box with same name.. the onenter() will get confused to set value to which box..

here i am writing script without any function so that it is called on the end of asp to reset the value.

Regards.

Viswanath AT.
0
 
appariCommented:
Sorry, what i mean is
change
Response.write  "<INPUT TYPE=text name = EnterPressedHidden  value = " & Request.Form("EnterPressedHidden")&"> "
to
Response.write  "<INPUT TYPE=text name = EnterPressedHidden  value = ''> "

and remove the block

<SCRIPT LANGUAGE=VBScript >      ' reset the value to zero.
document.Form1.EnterPressedHidden.value = 0    
</SCRIPT>

0
 
GaryCommented:
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:
Accept Answer by Hooligan
Please leave any comments here within the next seven days.
 
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
 
GaryC123
EE Cleanup Volunteer
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.