ASP.NET , dotnet , .net , javascript Tips and Tricks




Advance ASP.NET

Basic .NET

Advance .NET

Shortcut keys

Good time pass for IT Guys

  • How to run music in background in ASP.NET? HtmlGenericControl bgsound = new HtmlGenericControl("bgsound");
    bgsound.Attributes.Add("src", "mySound.wav");
  • Testing tools .Net                                                                  try
  • How to get start with Crawler
  • how to reset focus to a top of page                                  Place a hidden control at the top of page. and set focus on that control.
  • How to add more than one query in single Command Object by using ExecuteReader Command ?                                                                                      Use DataReaderObject = commandObject.ExecuteReader(); DataReaderObject.NextResult(); Add MultipleActiveResultSets=true to connection string.
  • How to disable right click in a browser?                     <script language="javascript" type="text/javascript">

    function disableclick(e)
    alert("Right Click Disabled");
    //return false;
  • Difference between Custom ASP.NET Control and User Control ?                                                          Custom ASP.NET server controls, we can encapsulate custom user interface and other functionality in controls that can be reused on ASP.NET pages

    We extend a particular our own control But in User control we does not build our own control as in case of Custom control, we just use the existing control functionality. Like in case of we needs a black dropdown so we needs to create a custom control. But I have to show same header on my all the pages I will create custom control.
  • How to get the javascript return value at C# code behind?                                                                                   Put a HTML input control with RUNAT = SERVER within the </form> tag.Assign the values to the this control using the javascript code. Then use Page.FindControl method to locate the control and extract the value from the control.
  • What are the disadvantages of using Eval?               It is important to note that DataBinder.Eval can carry a noticeable performance penalty over the standard data binding syntax because it uses late-bound reflection. Use DataBinder.Eval judiciously, especially when string formatting is not required.

    For more read at 2005/04/10/41485.aspx
  • Is there some limit using HTTP GET?                         256 character limit is with HTTP GET
  • Is there some limit using HTTP POST?                 No 
  • How to calculate number of sundays between two dates using javascript ?                                                 This script shows how to determine number of weeks:

    <script type="text/javascript">
         var day1=new Date()
         var day2=new Date()
         day2.setFullYear(2007,1,1) // month is declared as //jan = 0 feb = 1 etc., January 1st 2007 in this instance
         var numberDays = Math.ceil((day2.getTime() - day1.getTime()) / (86400000)) // 86400000 is //number of milliseconds in one day
         var numberWeeks = Math.ceil(numberDays / 7)
         document.write("Number of Days between today and January 1st: " + numberDays + "<br />")
         document.write("Number of Weeks between today and January 1st: " + numberWeeks + "<br />")

    Same method can also be used to determine number of sundays. 
  •   How to make a schedule to automated email using ASP.NET ?                                                                            You can use windows task scheduler or Windows services. You can write a windows console application in vb or c# that sends the mail, and the run it at a pre-dertimined time interval with the windows task scheduler. You can do this for a few different applications and it works flawlessly and link for windows service is provided below                                    /05/03/SchedulingASPNETCode/default.aspx
  • how to stop an ASP.NET application from continuing                                                                                         Use                                                                                                             response.write(" ")

  • How to create a message box in ASP.NET?                             Page.RegisterClientScriptBlock("MessageBox", "<script type=""text/javascript"">alert('Hello World');</script>")