Wednesday, August 4, 2010

How to prevent avoid Session Timeouts in an Asp.Net C# vb.net Page




Please visit my new Web Site https://coderstechzone.com



As we knew that its a very big problem specially when developers provide a very large entry page to users. It will be Irritating for users after entering all data & then session timeout occur. To prevent or avoid session timeout problem, there is no fixed or specific or direct way to handle. But one can handle this problem using javascript asynchronous call. But one thing keep in mind that time to execute the javacript method must be less than your session timeout time. Otherwise the method will not work. So, carefully set the time aganist IIS or web.config file session time. The cross-browser javascript method is given below:










<script language="javascript" type="text/javascript"> 
function Prevent_Session_Timeout() 
{ 
var callerurl = "Prevent_Session.aspx"; 

if (window.XMLHttpRequest) 
{ 
xhttp = new XMLHttpRequest() 
} 
else 
{ 
xhttp = new ActiveXObject("Microsoft.XMLHTTP") 
} 
xhttp.open("POST", callerurl, true); 
xhttp.send(""); 

window.setTimeout("Prevent_Session_Timeout();", 60000); 
} 

//Initial calling
Prevent_Session_Timeout(); 
</script> 

Important Notes:
1. Just create an aspx page named Prevent_Session.aspx. Because this page will be internally called by the above javascript method without any reflection to user.
2. You must set the window.setTimeout time parameter which never exceed the session timeout time of your project.
3. Paste the code in your main master page so that you need not write the code for each aspx page.

Script Tested for the following browsers:
1. Internet Explorer (IE)
2. Mozilla Firefox
3. Opera
4. Google Chrome

Tuesday, August 3, 2010

Maintaining Scroll Position after Asp.Net Page PostBack




Please visit my new Web Site https://coderstechzone.com



Sometimes we need to Maintain scroll position after page postback specially if the page is a large page & user need to work in the middle portion of the page. In this article i will give you a simple tips on How to maintain Scroll Position after Asp.Net Page PostBack. To do that in the Page Directive of your large Asp.Net Page, add the property 'MaintainScrollPositionOnPostback' and set its value as 'true'.












For Example:
<%@ Page Language="C#" CodeFile="Default.aspx.cs" MaintainScrollPositionOnPostback="true" Inherits="_Default" %> 
Now, the page will maintain the scroll bar position in the same location as it is before postback.

Monday, August 2, 2010

Error: Specified string is not in the form required for an e-mail address




Please visit my new Web Site https://coderstechzone.com



This error may occur when you are working with .net 1.1 means when using the namespace Sytstem.Web.Mail. If we want to send email to multiple or more than one person usually we use like:

To=aaaaaaa@gmail.com;bbbbbbbb@gmail.com;ccccccccc@gmail.com;

This will work in the namespace Sytstem.Web.Mail because here we use semicolon to split or separate email ID's.

But the ERROR: "Specified string is not in the form required for an e-mail address" will appear when we use semicolon as a separator in .net 2.0. Because the namespace System.Net.Mail in .net 2.0 framework will use comma as the email separator instead of semicolon. So we will use like below:

To="aaaaaaa@gmail.com,bbbbbbbb@gmail.com,ccccccccc@gmail.com";

Hope now your problem has been resolved.

Syntax of Shrinking SQL Server database mdf and log file




Please visit my new Web Site https://coderstechzone.com



The below code snippet will help you to shrink the database. Run the code snippet through your SQL Server query analyser.
















backup log <database_name> with truncate_only 
use <database_name> 
dbcc SHRINKFILE (<database_name_Log>,2) 
dbcc ShrinkDatabase (<database_name>, 2)
Want To Search More?
Google Search on Internet
Subscribe RSS Subscribe RSS
Article Categories
  • Asp.net
  • Gridview
  • Javascript
  • AJAX
  • Sql server
  • XML
  • CSS
  • Free Web Site Templates
  • Free Desktop Wallpapers
  • TopOfBlogs
     
    Free ASP.NET articles,C#.NET,VB.NET tutorials and Examples,Ajax,SQL Server,Javascript,Jquery,XML,GridView Articles and code examples -- by Shawpnendu Bikash