Click here to Skip to main content
15,886,199 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Actually i need a popup while leaving the page depending on the session value if the session value is null or empty it should say please enter data otherwise if the session value is not equal to empty or null it should not show any thing. is it possible
Posted
Comments
Karthik_Mahalingam 22-Jan-14 20:52pm    
"while leaving the page" means closing the browser ??
What you have tried?, post your code.

1 solution

This is impossible. The session lives on your server. You would have to pass down to the PAGE a behaviour when someone leaves the page, and it won't always run( for example, if someone closes the browser). You can, of course, emit javascript to your page on the basis of a session value.
 
Share this answer
 
Comments
ntitish 23-Jan-14 1:24am    
sir thanks for your reply......sir i had one more doubt, can i fire pop up in page_unload event in .cs
Christian Graus 23-Jan-14 1:27am    
Why do I get a 1 vote ( this is bad ) for giving a correct answer ?

You need to read about how the web works. All C# code runs on your server. No, you cannot fire a popup. You can't stop your whole page lifecycle from running for every page request. All you can do is emit the javascript to show a popup once the page life cycle has ended and the browser is showing the page.

I don't usually ask for votes, but if you voted me 1, please change it to a 5 if I helped, or explain why you gave me a bad vote. Marking my reply as the answer also helps me AND helps the site because it shows the question was answered.
ntitish 23-Jan-14 4:03am    
Sir actually i got one code while searching abut this issue.........

window.onbeforeunload = confirmExit;
function confirmExit()
{
return "your changes will be lost if not saved. Are you sure you want to exit this page?";
}

while applying this code i am unable to leave the current page.....my task is completed half.......
now the half task should be completed is
1.)two button click events the above code should not work and second condition
2.)using the session value it should work
3.) when i am applying this it is showing two options "stay on this page" and "leave this page" instead of this two options i need only one "Stay on this page"

by above points my code should be like this(assumption)
if(button1_click!=click or Button2_click!=click)
{
if(session["user"]=="A")
{
alert
}
else
{
No alert
}
]

sorry for above example but i am unable to explain properly. but like that i my logic should be is it possible
Christian Graus 23-Jan-14 4:08am    
Yes, you're right, that code is broken. You need to return the result of a prompt.

http://www.w3schools.com/js/js_popup.asp

A confirm box is what you need.

Still curious why you want my help, if you won't vote for my answer, and perhaps even down voted me.
ntitish 23-Jan-14 5:06am    
When i am using this below code i am getting two options "stay on this page" and "leave this page" but i want only stay on this page is it possible...........

window.onbeforeunload = confirmExit;
function confirmExit()
{
return "alert message for testing";
}

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900