How to Detect the user Close the page

Posted by Venkat | Labels:

You can use the onunload or the onbeforeunload events to execute codes when the browser is about to closed.

You may also use Page Methods, see below

http://aspalliance.com/1294_CodeSnip_Handle_Browser_Close_Event_on_the_ServerSide.all

The code below will simulates the closed button of the browser when the user invoked the button and display an alert message..

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
<script type="text/javascript">
function doSomething()
{
alert('Widnow is about to close');
}
</script>

</head>
<body onunload="doSomething();">
<form id="form1" runat="server">

</form>
</body&gt;

Small trick to hide HTML element

Posted by Venkat | Labels:

In this post I’m going to only show a simple trick how to hide an image by using XPath expression and by not adding “server side” code into codebehind or inside a server side script block. I got this simple idea from a post I recently answered on the ASP.Net forum. Maybe some other may find this useful.


<img runat="server" visible='<%# (XPath("@value") == "35" ) %>' src='<%# "images/" + XPath("@img") + ".gif" %>'>


The XPath expression for the @value attribute will return true if the value is 35, if not it will return false. The visible attribute that is added to the img element, can only hide an element if it’s turned into a html server control. That is done by adding the runat attribute.


Ref: http://fredrik.nsquared2.com/ViewPost.aspx?PostId=324

PayOffers.in