Quote for the Week

"Learn to enjoy every moment of your life"

Thursday, November 27, 2014

Showing Message Box in Asp.net

We don't have predefined function for message box or alert in asp.net web application. It's available only in windows application. But we can create our own method that gives alert functionality. Here the ClientScript used to add the script to the page. so we can get the javascript alert in page.


Page.ClientScript.RegisterStartupScript(this.GetType(), "MessageBox", <your javascript>);

or

ScriptManager.RegisterClientScriptBlock(Me, Me.GetType(), "Confirm", "Confirm('Text U want to display');", True);

You can define your own script as per your requirement.

Wednesday, November 19, 2014

Data Caching in Asp.net

Data Caching:

Data caching stores the required data in cache. So the web server did not send request to DB server every time for each and every request which increase the web site performance. Hence, caching of data can dramatically improve the performance by reducing database hits and round-trips.

We can do the caching like this,


HttpContext.Current.Cache.Insert("strCacheName","data you want to cache", null, DateTime.Now.AddMinutes(expTime), TimeSpan.Zero);

Parameters used:

key:
The cache key used to reference the object.

value:
The object to be inserted in the cache.

dependencies:
The file or cache key dependencies for the inserted object. When any dependency changes, the object becomes invalid and is removed from the cache. If there are no dependencies, this parameter contains null.

absoluteExpiration:
The time at which the inserted object expires and is removed from the cache. To avoid possible issues with local time such as changes from standard time to daylight saving time, use System.DateTime.Utc. Now rather than System.DateTime.Now for this parameter value. If you are using absolute expiration,the slidingExpirationparameter must be System.Web.Caching.Cache.NoSlidingExpiration.

slidingExpiration:
The interval between the time the inserted object is last accessed and the
time at which that object expires. If this value is the equivalent of 20
minutes, the object will expire and be removed from the cache 20 minutes
after it was last accessed. If you are using sliding expiration, the absoluteExpiration
parameter must be System.Web.Caching.Cache.NoAbsoluteExpiration.

Friday, November 14, 2014

How to disable copy , paste in text box using jQuery


  • Some times in validation point of view we need to disabled copy, paste, cut , like password or mobile number etc..,
  • We can achieve this using jQuery - 


$(document).ready(function(){
      $('#txtInput').bind("cut copy paste",function(e) {
          e.preventDefault();
      });
 });


That's it! It is very simple.

Have a Good Day.

Thursday, November 13, 2014

Simple validation technique using jQuery without any plug-ins


  • This Article subjected to How we do validation , As we have many validations with different plugins or jQuery validation.
  • Today I am going to show you how we can do validation using our own customize script at client-side.
  • Initially, we will add class called 'validation' to all text boxes which are required for ex: Name, Mobile, Email



First name: <input  type='text' id='txtName'  class='validation'/>

Phone : <input  type='text' id='txtPhone'  class='validation'/>

-----------------------
-----------------------

<input type='button' value='submit' id='btnSubmit' />

Now in script write as
<script>
$(document).ready(function(){
$("#btnSubmit").click(function(){

  $('.validation').each(function () {
            if ($(this).val() == "" || $(this).val()==0) {
                isValid = false;
                $(this).css({
                    "border": "1px solid red",
                    "background": "#FFCECE"
                });
            }
            else {
                $(this).css({
                    "border": "",
                    "background": ""
                });
            }
        });
});
});

</script>

That's simple, validation is Done. Do you want to try it, you can.


If any queries mail to dotnetcircle@gmail.com.

HAVE A GOOD DAY.


Monday, November 3, 2014

Difference between Response.Redirect and Server.Transfer


       In ASP.Net Technology both "Server" and "Response" are objects of ASP.Net. Server.Transfer and Response.Redirect both are used to transfer a user from one page to another. But there is some remarkable differences between both the objects which are as follow.


Response.Redirect

  1. Response.Redirect() will send you to a new page, update the address bar and add it to the Browser History. On your browser you can click back.
  2. It redirects the request to some plain HTML pages on our server or to some other web server.
  3. It causes additional roundtrips to the server on each request.
  4. It doesn’t preserve Query String and Form Variables from the original request.
  5. It enables to see the new redirected URL where it is redirected in the browser (and be able to bookmark it if it’s necessary).
  6. Response. Redirect simply sends a message down to the (HTTP 302) browser.



Server.Transfer


  1. Server.Transfer() does not change the address bar, we cannot hit back.One should use Server.Transfer() when he/she doesn’t want the user to see where he is going. Sometime on a "loading" type page.
  2. It transfers current page request to another .aspx page on the same server.
  3. It preserves server resources and avoids the unnecessary roundtrips to the server.
  4. It preserves Query String and Form Variables (optionally).
  5. It doesn’t show the real URL where it redirects the request in the users Web Browser.
  6. Server.Transfer happens without the browser knowing anything, the browser request a page, but the server returns the content of another.