Monday 30 June 2014

How to redirect one page to other in Asp.Net MVC 4?



window.location.href example: window.location is object that holds all information about current document location (host, href, port, protocol etc.). location.href is shorthand for window.location.href.They acting the same when you assign url to them - this will redirect to page which you assing, but you can see difference between them, when you open console (firebug, of developer tools) and write window.location and location.href

window.location.href = '@Url.Content("~/HTML/BrowserNotSupported.html")'; //Will take you to BrowserNotSupported.html.

window.open() example:

window.open('http://www.yahoo.com'); //This will open yahooin a new window.

Thursday 26 June 2014

when should you use “with (nolock)” in SQL?

WITH (NOLOCK) is the equivalent of using READ UNCOMMITED as a transaction isolation level. So, you stand the risk of reading an uncommitted row that is subsequently rolled back, i.e. data that never made it into the database. So, while it can prevent reads being deadlocked by other operations, it comes with a risk. In a banking application with high transaction rates, it's probably not going to be the right solution to whatever problem you're trying to solve with it IMHO.

How to apply CSS on Hidden Button in HTML

CSS file:--
#btnPost[disabled="disabled"] {
    background: none;
}

html file:-
<button type='submit' class='leftArrow' id='btnPost' disabled='disabled'>Post</button>

This css file is used to remove the backgraound of the button.

How to create Widget in JQUERY..

(function ($) {

    $.widget('AZ.azAddNewDiscussion', $.AZ.Node, {
        options: {
          data: null      
        },
        widgetEventPrefix: $.AZ.Node.prototype.widgetEventPrefix,

        _create: function () {               // create event
            this._addNewDiscussion();

            this._on(this.element, {
                'click': function (event) {              
                },
                'click #newDiscussionNode': function (event) {
                    alert('button click');
                }

            });
        },
        _addNewDiscussion: function () {
     
          var buttonElemet = $("<h6 id='newDiscussionNode' style='text-align: right;color: #FFFFFF;margin-right: 1em;'>New Discussion</h6>");
          $(this.element).append(buttonElemet);

        }

    });

})(jQuery);

How to add and remove attribute in JQuery..

Html tag :-
<button type='submit' class='leftArrow' id='btnPost' disabled='disabled'>Post</button>

Remove attribute in jquery--
 $('#btnPost').removeAttr("disabled");

Add attribute in jquery--
 $('#btnPost').attr("disabled", "disabled");

Tuesday 24 June 2014

Apply CSS depending on Input Type and Element type.

CSS file...

.upload-modal input[type="text"], textarea {

border-color: #DDDDDD;
border-style: solid;
border-width: 1px;
display: block;
font-family: roboto;
font-size: 0.9em;
margin: 0.5em 0;
padding: 0.5em 0;
resize: none;
width: 100%;
border-radius: 0.5em 0.5em 0.5em 0.5em;
-moz-border-radius: 0.5em 0.5em 0.5em 0.5em;
-webkit-border-radius: 0.5em 0.5em 0.5em 0.5em;
}

HTML file...
<div class="modal-dialog upload-modal">// two class is apply
<section>
<div class="secChild">
<input name="post" id="post" value="post" type="text">
</div>
<div class="secChild">
<textarea name="description" id="description">description</textarea>
</div>
<div class="secChild">
<input name="tag" id="tag" type="text" value="tag">
</div>
</section>
<div >
Apply above css depending on the element type and input type of all element of upload-modal .

Sunday 15 June 2014

two way add the ajax file into ASP.NET MVC 4


1. @Scripts.Render("~/bundles/jqueryval") into _Layout.cshtml file
2. <script src="~/Scripts/jquery-1.7.1.min.js"></script>
<script src="~/Scripts/jquery.unobtrusive-ajax.min.js"></script>--into current excution file

Wednesday 4 June 2014

Difference between Redirect and Transfer in ASP.NET

Response.Redirect should be used when:
  • we want to redirect the request to some plain HTML pages on our server or to some other web server
  • we don't care about causing additional roundtrips to the server on each request
  • we do not need to preserve Query String and Form Variables from the original request
  • we want our users to be able to see the new redirected URL where he is redirected in his browser (and be able to bookmark it if its necessary)
Server.Transfer should be used when:
  • we want to transfer current page request to another .aspx page on the same server
  • we want to preserve server resources and avoid the unnecessary roundtrips to the server
  • we want to preserve Query String and Form Variables (optionally)
  • we don't need to show the real URL where we redirected the request in the users Web Browser

Tuesday 3 June 2014

various of data Type in C#

protected:
The type or member can only be accessed by code in the same class or struct, or in a derived class.
internal:
The type or member can be accessed by any code in the same assembly, but not from another assembly.
protected internal:
The type or member can be accessed by any code in the same assembly, or by any derived class in another assembly

Event Example in C#

public class MyClass
    {
      
        public delegate void LogHandler(string message); //Delegate
 
        
public event LogHandler Log;  //event
 
 
   
        public void Process()          //method used to start event
        {
            OnLog("Process() begin"); 
            OnLog
("Process() end");
        }

        protected void OnLog(string message)
        {
            if (Log != null)
            {
                Log(message);  
            }
        }

    }

public class TestApplication
    {
        static void Logger(string s) // call back method after event is called
        {
            Console.WriteLine(s);
        }

        static void Main(string[] args)
        {
         
            MyClass myClass = new MyClass();
 
           
            myClass.Log += new MyClass.LogHandler(Logger); 

                      // add  method which do process after event fire
          
 
            myClass.Process();

                   
// The Event will now be triggered in the Process() Method
         }
           

   }

More Details

how to used the YIELD keyword.

public  class C
    {
     
     public IEnumerable< int> yieldMethod()
      {
         int i=1;
          for (i = 1; i < 5; i++)
                yield return i;
       }
   }

void .fun()
        {
            C obj1 = new C(10);
            foreach (var item in obj1.yieldMethod())
            {
                Console.WriteLine(item);
            }
           
     }

Output:--
1
2
3
4

Difference between '==' and 'Equals'

  void fun()
        {
                 
            object o1 = "chirag";
            object o2 = new string("chirag".ToCharArray());
            object o3 = "chirag";
         
            Console.WriteLine(o1 == o2); // false. both object are different.
            Console.WriteLine(o1 == o3);  // true . when creating o2 object, fatch data from
                                          //String pool and o2  
                                         //  get same object as o. becuase string class
                                         // override GetHashCode() method and it give same hash code.
            Console.WriteLine(o1.Equals(o2));// true. both object has content are same.
            Console.WriteLine(o1.Equals(o3));// true. both object has content are same.


             C obj1 = new C(10);
            C obj2 = new C(10);
            Console.WriteLine(obj1 == obj2); // false
            Console.WriteLine(obj1.Equals(obj2)); //false
            Console.ReadLine();
      }
 public  class C
    {
        int id;
      public C(int id)
        {
            this.id = id;

        }
   
    }
Output:
FALSE
TRUE
TRUE
TRUE.

-----------------------------------------------------------------------------
“==” compares if the object references are same while “.Equals()” compares if the contents are same.