Infolink

 

Search This Blog

Dec 19, 2013

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

<html>
<head>
<script type="text/javascript">

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

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

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

    </script>

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

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");
            try
            {
                MailMessage msg = new MailMessage();
                msg.From = new MailAddress("Test@MailServer.com", "Test System)");


                msg.Bcc.Add(toAddresses);
                msg.Subject = MailSubject;
                msg.Body = MessageBody;
                msg.IsBodyHtml = isBodyHtml;
                sc.Send(msg);
            }
            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.
                conn.Open();

                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();
                            sbEmailAddresses.Append(username).Append("@mailServer.com");
                        }
                    }

                    //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 />
resources.
                                    </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;
                av.LinkedResources.Add(linkedRes);


                SendNotificationByEmail(sbEmailAddresses.ToString(), "", "Welcome", body, true);
                sbEmailAddresses.Clear();
                reader.Close();
                }

                conn.Close();
            }
}

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

Solution:

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))
Solution
  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.
Related Posts Plugin for WordPress, Blogger...