page validation help

G

Guest

Hi all,
I needed to have a validation to prevent someone from leaving the page if
they added anything to it. I have about 10 imagebuttons at the top of the
page for menu selections, and i wanted to have a warningmessage pop up if
they select any of those without clicking the save button first.
I put :
If session("save") = "no" then
ImageButton1.Attributes.Add("onclick", "return confirm('Are you sure you
want to exit without saving?');")
end if...
in the page load event , and it works, but it will always show this message
now.. even if they selected the save button.

I use session variables to determine if it's been clicked, and in the page
load i check to see if the session var. is what its suppose to be, but it
will still always show it nomatter what...
What should i do???
 
C

chanmmn

Try to check for you logic and Ispostback event. Example:

Sub Page_Load
If Not IsPostBack
' Validate initially to force the asterisks
' to appear before the first roundtrip.
Validate()
End If
End Sub


chanmm
 
G

Guest

Thanks for the quick reply,
I'm not sure if i could use the postback option, because there are other
buttons and dropdowns which are used on the page, so many postback will occur
before the user enters info and clicks save...
its for a schedule page, so i have if there is a textchange in any of the
textboxes, then it should pop up with a message if the user hasn't clicked
save..
 
G

Guest

I've played around with the session variables, and now i sort of get it to
work...
if i make changes to the schedule page, and don't save anything, then i can
leave and go to another page, do whatever else, and the next time i go back
to the schedule page it will give me the "Are you sure" message for the
previous time.. and the next time will be this time's messages... so it's
pretty much always back one..
Just sucks the info is already gone when you leave the page, so the late
message is useless...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top