Thursday, July 14, 2011

Disable Right Click -Asp.Net


<script language="JavaScript">
      // on right click appear this message
      var DisplayMsg="Right Click Disabled";
      //return message
      function clickBYIE()
      {
          if(document.all)
          {
              alert(DisplayMsg);
              return false;
          }
      }
      //return message
      function clickBYNS(e)
      {
          if (document.layers||(document.getElementById&&!document.all))
          {
              if (e.which==2||e.which==3)
              {
               alert(DisplayMsg);
               return false;
              }
          }
      }

     //set the function as per browser
      if (document.layers)
      {
          document.captureEvents(Event.MOUSEDOWN);document.onmousedown=clickBYNS;
      }
      else
      {
          document.onmouseup=clickBYNS;document.oncontextmenu=clickBYIE;
      }
      //disabled the right click on the browser
       document.oncontextmenu=new Function("return false")
  </script>

Saturday, July 2, 2011

Set Default Button in ASP.NET


<form id="form1" runat="server" defaultbutton="Button1">

   <asp:TextBox ID="Textbox1" runat="server" />
   <asp:TextBox ID="Textbox2" runat="server" />

   <asp:Button ID="Button1" runat="server" Text="Submit" />
   <asp:Button ID="Button2" runat="server" Text="Cancel" />

</form>

Thursday, June 23, 2011

Embed youtube video without youtube link



<object style="height: 390px; width: 640px">
<param name="movie" value="http://www.youtube.com/v/u1zgFlCw8Aw?version=3">
<param name="allowFullScreen" value="true">
<param name="allowScriptAccess" value="always">
<embed src="http://www.youtube.com/v/u1zgFlCw8Aw?version=3" type="application/x-shockwave-flash" allowfullscreen="true" allowScriptAccess="always" width="640" height="390"></object>

Sunday, June 19, 2011

How to check the value in querystring is number or not in Asp.Net

if (!String.IsNullOrEmpty(Request.QueryString["Id"]))
 {
   string Id = Request.QueryString["Id"].ToString();

   if (Id != "")
     {
        int numeber = 0;
        if (int.TryParse(Id, out number))
          {
         //code
          }
         else
          {
            Server.Transfer("Error.aspx");
          }
     }
     else
      {
         Server.Transfer("Error.aspx");
}

 }

Wednesday, June 1, 2011

ASP.NET GridView And Conditional Images

Depending upon a value in the data source, we can conditionally display images in GridView columns. For example, the following TemplateField declaration conditionally displays approved.gif or unapproved.gif based on IsApproved flag in the DataSet that the GridView is bound to:


 <asp:TemplateField HeaderText="Approval Status"> 
<ItemTemplate> 
<asp:Image ID="ApprovalImage" runat="server" ImageUrl='<%# "~/Images/" + (((bool)Eval("IsApproved") == false) ? "Unapproved.gif" : "Approved.gif") %>' /> 
</ItemTemplate> 
<ItemStyle Width="25px" /> 
</asp:TemplateField> 

Ajax CalendarExtender displaying at wrong position in Chrome

< script type ="text/javascript" language ="javascript">     function onCalendarShown(sender, args)...