Monday, February 22, 2016

How to use Toastr.js in ASP.NET

First let me ask you a question, what is Toastr.js and what is the use of it?

Toastr is a simple JavaScript library which can be used along with jQuery to show a simple and appealing notification in your web application. Good thing about Toasr is, since it is a JavaScript library it won’t create any performance issue and the coding looks very simple.

Lets start with a very simple .net application with one label, textbox and a button. Then on click of the button we will show the Toastr alert.

image

First we need to add the Toastr library like below in your .aspx page.

<script src="http://code.jquery.com/jquery-1.9.1.min.js" type="text/javascript"></script>
   <Link href="https://cdnjs.cloudflare.com/ajax/libs/toastr.js/2.0.1/css/toastr.css" rel="stylesheet" />
   <script src="https://cdnjs.cloudflare.com/ajax/libs/toastr.js/2.0.1/js/toastr.js" type="text/javascript"></script>

Here you might have noticed that I am referring the path directly from the online URL. In your case you may download the toast.js and toastr.css and also the jQuery and refer it internally.

Now we will write the code to show the alert.

protected void Button1_Click(object sender, EventArgs e)
       {
           Page.ClientScript.RegisterStartupScript(this.GetType(),"toastr_message", "toastr.error('Please Enter Name', 'Error')", true);
       }

On click of the button Toastr message will be shown like below. You can have a condition based on your requirement to show the alert.

Here I didn’t show that because everyone got their on requirement.

image

You have many option to show different color, different title and different icon depends on the message.

Another sample below is for success,

image

Similarly you have toastr.info and toastr.warning to show the alert.

Another useful option you may require is the position where you want to show the alert.

Below are some of the options available in toastr,

toastr.options = {
  "closeButton": false,
  "debug": true,
  "newestOnTop": true,
  "progressBar": false,
  "positionClass": "toast-top-right",
  "preventDuplicates": false,
  "showDuration": "300",
  "hideDuration": "1000",
  "timeOut": "5000",
  "extendedTimeOut": "1000",
  "showEasing": "swing",
  "hideEasing": "linear",
  "showMethod": "fadeIn",
  "hideMethod": "fadeOut"
}
I hope you enjoyed reading this article. Please try this in your project and let me know your client feedback. I am sure they will definitely like this.

Friday, February 19, 2016

The underlying provider failed to open error in C#

 

This is one of the very common error we use to get while using Oracle database. The error “The underlying provider failed to open” is bit confusing if you are not able to view the inner exception.

Once you get the exception, just expand the exception try to read the inner exception. Whihc will be more clear than this.

I just exapanded the exception and the actual error we get is “ORA – 12154: TNS:could not resolve the conect identifier… ” If you read this exception it will be more clear and you might know what needs to be done.

Below is the screen print of the error.

image

I assume you have installed Oracle client in your machine. This error just because you missed the 3 required files

1. tnsnames.ora

2. sqlnet.ora

3. ldap.ora

So in order to resolve the error “ORA – 12154: TNS:could not resolve the conect identifier…” you have to copy three files to the oracle installation location.

Oracle installation folder may vary depends on where you have installed the software and the windows version.

I have given you two possible location normally oracle get installed.

C:\app\client\<Userid>\product\12.1.0\client_1\network\admin

or

C:\Oracle\product\12.1.0\client_1\Network\Admin

If you cannot find Network and Admin folder in Client_1 path you may create those two folders.

Now you try to run the code and see if the issue gets resolved or not.

I hope it helps you to resolve the issue.

Thanks you for visintg my blog.