Sunday, September 25, 2011

Display alert before redirect in asp.net

 ScriptManager.RegisterStartupScript(Me, Me.GetType(), "message", "alert('Thank for posting your comment. You will now be redirected to our home page.');location.href = 'EntryMaster.aspx'", True)

Saturday, September 24, 2011

How To Block F5(Refresh) Key In IE and Firefox


<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
    <title>Block F5 Key In IE & Mozilla</title>

    <script language="JavaScript">

        var version = navigator.appVersion;

        function showKeyCode(e) {
            var keycode = (window.event) ? event.keyCode : e.keyCode;

            if ((version.indexOf('MSIE') != -1)) {
                if (keycode == 116) {
                    event.keyCode = 0;
                    event.returnValue = false;
                    return false;
                }
            }
            else {
                if (keycode == 116) {
                    return false;
                }
            }
        }

    </script>

</head>
<body onload="JavaScript:document.body.focus();" onkeydown="return showKeyCode(event)">
</body>
</html>

How To Stopping Your User From Right -Clicking


Want to prevent your user from performing any of the other commands available by right-clicking on a Web page in Internet Explorer? It’s not foolproof, but this neat little HTML edit usually does the trick.
Just alter the opening <body> tag of your HTML to the following:


<body oncontextmenu="return false">

When the menu is requested, the oncontextmenu event runs, and we instantly cancel it using JavaScript. This is especially potent as a method for stopping the user from viewing your source, when used in conjunction with a menu-less browser window. Great stuff!

Get list of all active session variables in ASP.NET


In this post I am going to discuss about  how you can get list of all active Session Variables in ASP.NET Application. The easiest way to get the details of session variable is using “Tracing” . If you enable the “Tracing” for your application, you can get list of all  Active Session variables. Another alternative way is, get all the list of session variable using “Session.Contents”.
To illustrate,  Let me store some dummy data to in some session variables,
image
Now, if you enable tracing in your page and inspect the Session State section, you will get the list of all session variable along with their type and values.
image
Now, if you want to read the same session variable programmatically, you have to use “Session.Contents”. Session.Contents returns the current System.Web.SessionState.HttpSessionState
image

Once done, you will get below details (here sessionItems is a multiline Text here )
image
Hope this will help you !!

Maintain Scroll Position After Postback in Asp.Net 2.0 3.5

Method 1 .

Write below mention directive in page directive section of html source of aspx page to maintain scroll position of only one page or selected pages rather then whole web application.
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs"  
         MaintainScrollPositionOnPostback="true"  Inherits="_Default" %>



Method 2. 

To maintain scroll position programmatically use code mentione below.
System.Web.UI.Page.MaintainScrollPositionOnPostBack = true;


Method3.

To maintain scroll position application wide or for all pages of web application we can write below mentioned code in pages section of web.config file so that we don't need to add page directive in each and every page.

<pages maintainScrollPositionOnPostBack="true">