Search This Blog

Dec 19, 2013

How to display a button on page after a period of time in ASP.NET?

<script type="text/javascript">

        function showButton()
            document.getElementById("btnContinue").style.visibility = "visible";

        function hideButton()
            document.getElementById("btnContinue").style.visibility = "hidden";

        window.onload = function()
            setTimeout('showButton()', 12000);


<input type="button" id="btnContinue" value="Continue" />

How to send an image with this customized C# Mail function?

C# Mail Function:

    /*For sending an email notification to the new user*/
        protected void SendNotificationByEmail(string toAddresses, string fromAddress, string MailSubject, string MessageBody, bool isBodyHtml)
            SmtpClient sc = new SmtpClient("MailServer");
                MailMessage msg = new MailMessage();
                msg.From = new MailAddress("", "Test System)");

                msg.Subject = MailSubject;
                msg.Body = MessageBody;
                msg.IsBodyHtml = isBodyHtml;
            catch (Exception ex)
                throw ex;


        protected void Send(string username)
            string connString = "Data Source=localhost\\sqlexpress;Initial Catalog=TestDB;Integrated Security=True";

            string networkID = username.ToString();
            using (SqlConnection conn = new SqlConnection(connString))
                var sbEmailAddresses = new System.Text.StringBuilder(2000);

                //initiate the varibles
                string name = null;

                // Open DB connection.

                string cmdText2 = @"SELECT     Name
                                    FROM       dbo.employee
                                    WHERE     (Username = @networkID)";
                using (SqlCommand cmd = new SqlCommand(cmdText2, conn))
                    cmd.Parameters.AddWithValue("@networkID", networkID);
                    SqlDataReader reader = cmd.ExecuteReader();
                    if (reader != null)
                        if (reader.Read())
                            name = reader["Name"].ToString();

                    //var sEMailAddresses = sbEmailAddresses.ToString();
                    string body = @"Good day "
                                    + name +
                                    @", <br /><br />
                                    You have been added to the <a href='http://localhost/TestSys'>Test</a>.
                                    <br /><br />
                                    </b> <br /> <br />
                                    <img src='images/Admin/EmailNotification.jpg' alt=' Message'/>

                string imagePath = Server.MapPath("~") + "\\";
                string fileName = imagePath + "EmailNotification.jpg";
                AlternateView av = AlternateView.CreateAlternateViewFromString(body, null, MediaTypeNames.Text.Html)
                LinkedResource linkedRes = new LinkedResource(fileName);
                linkedRes.ContentId = "image1";
                linkedRes.ContentType.Name = fileName;

                SendNotificationByEmail(sbEmailAddresses.ToString(), "", "Welcome", body, true);


Crystal Report Error Logon failed.Details:crdb_adoplus: Object Reference not set to an instance of an object

Error Description:

Logon failed. Details: crdb_adoplus : Object reference not set to an instance of an object. Error in File C:\DOCUME~1\XXX\LOCALS~1\Temp\XXXX {3309D862-8288-4B18-AEC2-FA3B78AA2BA3}.rpt


Check the field explorer. Then select Database Expert. Make sure that the tables selected matches in the xxx.aspx file consists of properties Report datasource in CrystalReportSource control

Crystal Report Error in ASP.NET C# : The system cannot find the path specified.

The system cannot find the path specified.

System.Runtime.InteropServices.COMException: The system cannot find the path specified.

Solution :
Configure the Report source properly. Make sure the path of the file rpt is correct.

Crystal Report Viewer Error in ASP.Net

Invalid index. (Exception from HRESULT: 0x8002000B (DISP_E_BADINDEX))

System.Runtime.InteropServices.COMException: Invalid index. (Exception from HRESULT: 0x8002000B (DISP_E_BADINDEX))
  1. Go To xxx.rpt and click at the fields eplorer.
  2. Select the Database fields.
  3. Right Click the table for Set Datasource Location.
  4. Match The Tables in Current Data Source and Replace With for Update. Click Close
  5. Verify Database.
  6. The Database is uptodate message will appear and hopefully no error after this.

Dec 15, 2013

Asynchronous Methods PART-2

Everybody would agree that asynchronously-served requests are important for the performance of potentially-lengthy operations. Taking this point to the limit, Windows 8 is highly dependent upon asynchronous operations and that is the preferred way of coding in the newest platform.

So what’s the real benefit of implementing asynchronous requests?

The benefits of asynchronous requests are entirely for the server environment. In ASP.NET, async HTTP handlers keep the server runtime much more responsive by guaranteeing that a larger number of threads are available at any time to serve requests. In the end, it won’t so much be the requests for long-running tasks that benefit from async handlers, but all other requests, for images, scripts, and other static and ASPX pages. In this way, the site remains highly responsive for all users and long-running requests will still take their time to complete. 

Asynchronous Methods PART-1

In general, use synchronous methods for the following conditions:
  • The operations are simple or short-running.
  • Simplicity is more important than efficiency.
  • The operations are primarily CPU operations instead of operations that involve extensive disk or network overhead. Using asynchronous methods on CPU bound operations provides no benefits and results in more overhead.
  • In general, use asynchronous methods for the following conditions:
  • You're calling services that can be consumed through asynchronous methods, and you're using .NET 4.5 or higher.
  • The operations are network-bound or I/O-bound instead of CPU-bound.
  • Parallelism is more important than simplicity of code.
  • You want to provide a mechanism that lets users cancel a long-running request.
  • When the benefit of switching threads out weights the cost of the context switch. In general, you should make a method asynchronous if the synchronous method blocks the ASP.NET request thread while doing no work.  By making the call asynchronous,  the ASP.NET request thread is not blocked doing no work while it waits for the web service request to complete.
  • Testing shows that the blocking operations are a bottleneck in site performance and that IIS can service more requests by using asynchronous methods for these blocking calls.

Oct 29, 2013

Gridview in disconnected mode


using BusinessLayer;
using PropertyLayer;
using System.Data.SqlClient;

namespace Gv_Disconnected_NTier_
    public partial class Gv_DisconnectedMode : System.Web.UI.Page
        DataTable d1 = new DataTable();

        protected void Page_Load(object sender, EventArgs e)
            if (Page.IsPostBack == false)
                GvBusinessLayer objBusinessLayer = new GvBusinessLayer();
                d1 = objBusinessLayer.GetStudentDetails("student_records");
                ViewState["d1"] = d1;
                 d1 = (DataTable)ViewState["d1"];

May 30, 2013

Create Folder Programatically with Database


string appPath = Request.PhysicalApplicationPath.ToString();

            DirectoryInfo newDirectory = new DirectoryInfo(appPath + txtName.Text);
            BAL obj1 = new BAL();
            DataTable dt = new DataTable();
            SqlParameter []p =new SqlParameter[1];
            p[0]=new SqlParameter("@FName",txtName.Text);
            string chk= obj1.ExecuteScaler("SP_CreateFolder", p);
            if (!newDirectory.Exists)
            else if (chk == "1")
                ClientScript.RegisterClientScriptBlock(this.GetType(), "", "<script>alert('Already Exists');</script>");

May 21, 2013

SQL Server Ranking Functions

SQL Server 2005 introduced new ranking functions. This article is tailored as an introduction to these functions, difference between them and when to use each and a few examples.
Related Posts Plugin for WordPress, Blogger...