Tuesday 10 February, 2009

Visual Studio 2010 & .Net Framework 4.0


I found an Article about Visual Studio Team System (VSTS) 2010. I was amazing to see the Microsoft Announcement. Microsoft Announce that this Framework as .Net Framework 4.0 and it code name is “Rosario”. The main features are collaborative development, modeling, and debugging.

Blog all about Dotnet Technologies...............





Most Useful JavaScript Functions :





 a superb blog............................ 

Creating PDFs on Fly with ASP.Net for Free of Cost

Link : - http://ramcrishna.blogspot.com/2008/10/creating-pdfs-on-fly-with-aspnet-for.html

SmartNavigation Vs MaintainScrollPositionOnPostback in ASP.net 2.0

MaintainScrollPositionOnPostback in ASP.net 2.0

Every one of us know very well about the feature of "SmartNavigation", BUT In Visual studio version 2.0 and above "SmartNavigation" has become obsolete. Now What is the alternate for this, if you want to achieve same feature as "SmartNavigation" then use "MaintainScrollPositionOnPostback".

How to use

Just set Page.MaintainScrollPositionOnPostback = true in page load event and java script will be inserted into your rendered page that maintains the scroll position in the browser window for all post back.
Believe me it's really a good feature in ASP.net 2.0, it would reduce lots of coding effort to maintain scroll position in web page.

Another alternate to maintain page scroll position

This way is same what we do for HTML documents. The following lines you can write into the server side or client side. Below example to write in server side

StringBuilder maintainScrollPosition = new StringBuilder();

maintainScrollPosition.Append("");

Page.ClientScript.RegisterStartupScript(this.GetType(), "Contents", maintainScrollPosition.ToString());

Here entity[0] has a value where you want to set scroll position, in other word it's a flag.You can assume entity[0] is heading in your aspx page and after postback you want scroll position be on this heading.

Keyboard Shortcuts in VS.NET.....

Keyboard Shortcuts in VS.net

Comment/Uncomment Code Blocks - Ctrl + K + C / Ctrl + K + U
Show tip - Ctrl + Shift + Space
List Methods/Properties - Ctrl + Space
Build - Ctrl + Shift + B
Expand All Outlining - Ctrl + M + L
Toggle Outlining - Ctrl + M + M
Toggle Breakpoint - F9
Clear all Breakpoints - Shift + F9
Add Existing Item dialog - Shift + Alt + A
Add New Item dialog - Ctrl + Shift + A
Properties Window - F4
Code and Design Window - F7 and Shift + F7
Move to Next Bookmark - Ctrl + K + N
Move to Previous Bookmark - Ctrl + K + P
Selected text to Uppercase - Ctrl + Shift + U
Selected text to Lowercase - Ctrl + U
Toggle Bookmark on Current Line - Ctrl + K + K
Select Word Containing Cursor - Ctrl + W
Sizing Controls Height - Shift + Down / Ctrl + Shift + Down
Sizing Controls Width - Shift + Right / Ctrl + Shift + Right
Find Dialog - Ctrl + F
Solution Explorer Window - Ctrl + Alt + L
Toolbox - Ctrl + Alt + X
Navigate Backward - Ctrl + hyphen
Incremental Search - Ctrl + I
Clipboard Ring - Ctrl + Shift + V
Word-Wrap in Editor - Ctrl + R + R
Block Selection - Alt and Drag
Full Screen Mode - Shift + Alt + Enter

How to Handle browser “Back” button using ASP.NET

Handling browser "Back" button using ASP.NET
 
To disable browser "Back" button
 
1) Very first and simplest way to disable the browser back button is  
 
<script language="JavaScript">
  javascript:window.history.forward(0);                     
script>
 
  Using this user can't use back button from browser to see previous page.
 
2)  Here if user redirect to error page then on the body onload we can call the following function so that user can not use back button at all, here we are redirecting same page again and again.
 
<script language="JavaScript">   
    function DisablingBackFunctionality()
    {
        var URL;
        var i ;
        var QryStrValue;
        URL=window.location.href ;
        i=URL.indexOf("?");
        QryStrValue=URL.substring(i+1);
        if (QryStrValue!='X')
        {
            window.location=URL + "?X";
        }
    }
script>
  
To close the browser window
 
Following are the alternate to handle browser "Back" button, like if you have an error in your application and you are redirecting to error page now from this error page user should not use browser back button to see the previous page.
We have to close the window by giving some alert error message, below some script to do so
 
1) To close the browser use
 
window.close() OR  this.close()  OR  document.close()
 
2) To close the browser without prompt use
           
window.opener = top;
window.close(); OR this.close()  OR  document.close()
  
3) If you want to give some alert message to close the page and if user click "OK" then close the browser then call following function in body  onload="check_form()"
 
<script language="JavaScript">
      var submitted=false;
      function check_form()
{
            if (submitted == true)
{
  alert ("Form already submitted") ;
  return false;
            }
      else
{
            submitted = true ;
      document.frmError.submit();
window.status ="Session expired. Please restart";
      window.opener = top;
alert("Please close this window.");
      window.close();
      }
      }
script>
 
4) If you want to close the browser automatically after few second then use following script in your aspx page
 
<script language="JavaScript">
 
   var bloodythief = 5;
    {
      alert("Window will close after 5 second.");
      window.setTimeout("window.close()",bloodythief*1000);
      window.opener = top;
    }
 
  script>
 
 
5)If you want ot disable browser Referesh or F5 button then use following script in your aspx page
 
    <script>       
  window.history.forward(1);
        document.attachEvent("onkeydown", my_onkeydown_handler);
        function my_onkeydown_handler()
        {
            switch (event.keyCode)
      {
            case 116 : // 'F5'
            event.returnValue = false;
            event.keyCode = 0;
            window.status = "We have disabled F5";
            break;
            }
          }             
      script>
 
Redirect to login page
 
6) All the above solution not seem to be compatable in other browser (Mozilla,Netscape etc), actually Window.close() function not works properly in others browser.To work in properly in other browser you have to close the parent window then open new window, it's kind of redirecting to login page if session expire.
 
This Supports all browsers.
 
<script language="JavaScript">
   
        function RedirectToLoinPage()
        {
            window.opener=self;
            var URL = window.location.href;
            if (URL.indexOf('Session') == -1)
            {
                alert('Not authorized to view this application.');
            }
            else
            {
                alert('Session expired.');
            }
            window.close();
            window.open('Login.aspx','Login','');
            }
script>
 
8) Another way to close the browser in other browsers
 
<script language="JavaScript">
function closeMe()
{
var win=window.open("","_self");
win.close();
}
script>
 
Imp: if the user has disabled JavaScript, then above java script won't work.
When user use "back" button to see previous page and submitting that page again then handle in the code behind also and redirect him to login page.
 
Session.Abandon() method to expire session and check in each page page_load event if (!Session.IsNewSession && Session["UserId"] == null) if session is null then redirect to login page.

How to do auto page refresh in ASPX

If you have a requirement something like auto redirect page to login page or auto refresh the current window within 10 sec or auto close window after 10 sec then you can write some lines of code in java script to achieve this

There are multiple ways to auto refresh/auto close browser, some very simple ways are below with examples.

1) Auto page refresh à you can write below code inside tag on top of your ASPX page
<head runat="server">
<meta http-equiv="Refresh" content="10;url=''">
head>
Note: Content takes two parameter 1)
2)

2) Auto page redirect à you can write below code inside tag on top of your ASPX page

<head runat="server">
<meta http-equiv="Refresh" content="10;url='http://localhost/Home/Login.aspx'">
head>
Note:
http-equiv="Refresh" à This tag will do page auto refresh
content="," à action when page refresh

3) Auto new page open à If you want to open new window after 10 sec then you can create a java script function say "OpenNewWindow" and use this function like below

<head runat="server">
<meta http-equiv="Refresh" content="10;url='javascript: OpenNewWindow('http://localhost/Home/Login.aspx',650,1000)">
head>

Note: content="," , 650 =height 1000= width.

function OpenNewWindow(url, h, w)
{
window.open(url,"","width=" + w + ",height=" + h + ",scrollbars=yes,resizable=yes,toolbar=yes,menubar=yes,location=yes,
directories=no,status=yes,left=5,top=5");
}

4) Auto page close à if you want to close the browser after 10 sec then write below code on top of your ASPX page
<script language="JavaScript">
var timestamp= 10;
{
window.setTimeout("window.close()",timestamp*1000);
window.opener = top;
}
script>
//OR
<script language="JavaScript">
window.setTimeout("window.close()",10*1000);
script>