Saturday, March 31, 2012

Datetime Convertion in mssql



select CONVERT(varchar(35),GETDATE(),100) -- Mar 22 2012 11:35AM
select CONVERT(varchar(35),GETDATE(),101) -- 03/22/2012
select CONVERT(varchar(35),GETDATE(),102) -- 2012.03.22

select CONVERT(varchar(35),GETDATE(),103) -- 22/03/2012
select CONVERT(varchar(35),GETDATE(),104) -- 22.03.2012
select CONVERT(varchar(35),GETDATE(),105) -- 22-03-2012


select CONVERT(varchar(35),GETDATE(),106) -- 22 Mar 2012
select CONVERT(varchar(35),GETDATE(),107) -- Mar 22, 2012
select CONVERT(varchar(35),GETDATE(),108) -- 11:40:04

select CONVERT(varchar(35),GETDATE(),109) -- Mar 22 2012 11:40:15:730AM

select CONVERT(varchar(35),GETDATE(),110) -- 03-22-2012
select CONVERT(varchar(35),GETDATE(),111) -- 2012/03/22

select CONVERT(varchar(35),GETDATE(),112) -- 20120322
select CONVERT(varchar(35),GETDATE(),113) -- 22 Mar 2012 11:41:07:593


select CONVERT(varchar(35),GETDATE(),120) -- 2012-03-22 11:46:37
select CONVERT(varchar(35),GETDATE(),121) -- 2012-03-22 11:46:49

select CONVERT(varchar(35),GETDATE(),126) -- 2012-03-22T11:47:49.
select CONVERT(varchar(35),GETDATE(),127) -- 2012-03-22T11:48:01
 

passing the array values from server side and getting from javascript in asp.net


function GetDatabyUsercontrol(Header, CId, Type) {
             var TypeArray = new Array();
             TypeArray = "'" + Type[0] + "','" + Type[1] + "','" + Type[2] + "','"  + Type[3] + "','"
                       + Type[4] + "','" + Type[5] + "'";  
}


ScriptManager.RegisterStartupScript(Page, this.GetType(), "Popup",
                        "callParentPageMethod('" + objVal.ToString() + "'," + objVal1.ToString() + ",[" + TypeofRequest + "]);", true);



passing the array values from server side and getting from javascript in asp.net

CompareOrdinal


int ival = string.CompareOrdinal("http://", 0, objFileName.ToString(), 0, 6);
 

Friday, March 23, 2012

Print Values from 5 to 1



string strOp = string.Empty;
int j=5;
     for (int i = 1; i <= j; i++)
     {
         strOp += i.ToString() + "&nbsp;";
         if (i == j)
         {
            j = j - 1;
            i = 0;
            strOp += "<br/>";
         }
     }
    
 Response.Write(strOp);

Output  :

1 2 3 4 5
1 2 3 4
1 2 3
1 2
1

Sunday, March 18, 2012

FindByValue for DropDownList in asp.net

Cannot have multiple items selected in a DropDownList.
The solution is to remember to call ClearSelection() Method before calling FindByValue("strValue") or FindByText("strtext") Method. 


dropDownList1.ClearSelection();
dropDownList1.Items.FindByValue("strValue").Selected = true; 

ASP.NET Ajax PageMethods

Ajax PageMethods in asp.net

<script type="text/Javascript">
function CallPageMethod()
{
var sDate= document.getElementById('<%=txtSDate.ClientID%>').value;
var eDate=document.getElementById('<%=txtEDate.ClientID%>').value;
PageMethods.GetValue(sDate, eDate);
}
</script>
  
.aspx.cs

[WebMethod]
 public void GetValue(DateTime dtsDate,DateTime dtEDate)
 {
    Cert.StartDate = dtsDate;
    Cert.EndDate = dtEDate;
 }

Set the iframe src from javascript in asp.net

how to set the iframe src from javascript in asp.net




var iframesrc = "../ChildPages/Search.aspx?sDate='" + sDate + "'&&eDate='" + eDate + "'";
document.getElementById("iframesearch").setAttribute("src", iframesrc);  // set the attribute for control


<iframe id="iframesearch" src=""></iframe>



Javasctipt to restrict the delete and backspace button

keypress,copy the text and paste the text in text box in asp.net


 <asp:TextBox ID="txtEDate" runat="server" onkeypress="return false;" oncopy="return false;"
                     oncut="return false;" onpaste="return false;" onkeydown="CheckKey() ;" Width="152px"></asp:TextBox>

Javasctipt to restrict the delete and backspace button press on textbox
onkeydown="CheckKey() ;"


<script type="text / Javascript">
 function CheckKey() 
{
          var keyCode = (event.which) ? event.which : event.keyCode;
          if ((keyCode == 8) || (keyCode == 46))
              event.returnValue = false;
 }
</script>

Between two dates dataview row filter

The expression contains unsupported operator 'Between'.
Instead of between opertor we can use the ' <= ' and ' >= '

DataView dview_certificates = table.DefaultView;
if (Session["StartDate"] != null && Session["EndDate"] != null)
 {
  //strRowfilter = "(StartDate between '" + DateTime.Parse(Session["StartDate"].ToString()).ToShortDateString();
//strRowfilter += "' and '" + DateTime.Parse(Session["EndDate"].ToString()).ToShortDateString();
//strRowfilter += "') or (FinishDate between '" + DateTime.Parse(Session["StartDate"].ToString()).ToShortDateString();
//strRowfilter += "' and '" + DateTime.Parse(Session["EndDate"].ToString()).ToShortDateString() + "')";
strRowfilter = "(StartDate >= '" + DateTime.Parse(Session["StartDate"].ToString()).ToShort

DateString();
strRowfilter += "' and StartDate <='" + DateTime.Parse(Session["EndDate"].ToString()).ToShort

DateString();
strRowfilter += "') or (FinishDate >= '" + DateTime.Parse(Session["StartDate"].ToString()).

ToShortDateString();
strRowfilter += "' and FinishDate <= '" + DateTime.Parse(Session["EndDate"].ToString()).
ToShortDateString() + "')";
dview_certificates.RowFilter = strRowfilter;
}

Encode / Decode in asp.net


How to encode the text in asp.net / How to Decode the text in asp.net

<asp:TextBox ID="txtSDate" runat="server" onkeypress="return false;" oncopy="return false;" oncut="return false;" onpaste="return false;" Width="152px"></asp:TextBox>

 public static string base64Decode(string sData)
 {
    try
    {
    System.Text.UTF8Encoding encoder = new System.Text.UTF8Encoding();
System.Text.Decoder utf8Decode = encoder.GetDecoder();
byte[] todecode_byte = Convert.FromBase64String(sData);
int charCount = utf8Decode.GetCharCount(
todecode_byte, 0, todecode_byte.Length);
char[] decoded_char = new char[charCount];

utf8Decode.GetChars(todecode_byte, 0, todecode_byte.Length, decoded_char, 0);
string result = new String(decoded_char);
  return result;
   }
 catch (Exception ex)
 {
     throw new Exception("Error in base64Decode" + ex.Message);
 }
}
public static string base64Encode(string sData)
 {
  try
   {
     byte[] encData_byte = new byte[sData.Length];
 encData_byte = System.Text.Encoding.UTF8.GetBytes(sData);
 string encodedData = Convert.ToBase64String(encData_byte);
 return encodedData;
  }
 catch (Exception ex)
 {
       throw new Exception("Error in base64Encode" + ex.Message);
 }
}
protected void btnSave_Click1(object sender, EventArgs e)
{
   string str = base64Encode(txtEncrypt.Text);
    lblEncrpt.Text = str;
}
protected void btnSave_Click2(object sender, EventArgs e)
{
 string str = base64Decode(txtEncrypt.Text);
 lblEncrpt.Text = str;
}

Nullable int in asp.net

nullable int with ternory operator in asp.net 

iCompanyId = Session["PCompanyId"].ToString()!= "null" ? int.Parse(Session["PCompanyId"].ToString()) : (int?)null;

Session State in a Web Service

Using Session State in a Web Service

[WebMethod (EnableSession = true)]
public string[] GetEmployeeName(string prefixText, string contextKey)
{

}


Avoiding the flicker in the Panel

While Using ajax modal popup extendar, then For avoiding the flicker in the Panel add the attributes like: Style="display: none"



<asp:Panel ID="pnlPopup" runat="server"style="display: none"> 

Jquery Conflicts in asp.net

jQuery.noConflict() is used for avoid the ajax and jquery Conflicts.or it can prevent the ajax and jquery Conflicts.


<script type="text/javascript">
 jQuery.noConflict();
</script>

Call a ServerSide Script through Javascript

How to call a ServerSide Script through Javascript

public void testData()
    {
        String cbReference = Page.ClientScript.
GetCallbackEventReference(
this, "arg", "ReceiveServerData", "context");
        if (!ClientScript.
IsClientScriptBlockRegistered("CallServer"))
        {
            String callbackScript;
            callbackScript = "function CallServer(arg, context)" +
            "{" + cbReference + ";}";
            Page.ClientScript.
RegisterClientScriptBlock(this.GetType(), "CallServer", callbackScript, true);
        }
    }
protected string returnValue;
    public void RaiseCallbackEvent(String assetid)
    {
        returnValue = assetid;
        //if (LoadHandler != null)
        //    LoadHandler(assetid);
       returnValue= GetDataByAssetIdforCertificate
s(Convert.ToInt32(assetid));
    }
    public String GetCallbackResult()
    {
        StringWriter sw = new StringWriter();
        HtmlTextWriter htw = new HtmlTextWriter(sw);
        TList<IcEquipmentDetails> tlst_eqdetails = new TList<IcEquipmentDetails>();
        tlst_eqdetails = obj_Equipmentdetails.GetAll();
//.ApplyFilter("Status=true");

        if (tlst_eqdetails != null)
        {
            ddlplantEqpmentIsolation.
Items.Clear();
            ListItem firstItem = new ListItem("------Select------", "-1");
            tlst_eqdetails.Filter = "Status = true";
            ddlplantEqpmentIsolation.
DataSource = tlst_eqdetails;
            ddlplantEqpmentIsolation.
DataTextField = "Name";
            ddlplantEqpmentIsolation.
DataValueField = "ID";
            ddlplantEqpmentIsolation.
DataBind();
            //GVLookupEmp.DataSource = tlst_eqdetails;
            //GVLookupEmp.DataBind();

            ddlplantEqpmentIsolation.
Items.Insert(0, firstItem);
        }
        else
        {
            ddlplantEqpmentIsolation.
DataSource = null;
            ddlplantEqpmentIsolation.
DataBind();
        }
        ddlplantEqpmentIsolation.
RenderControl(htw);
        //return GetDataByAssetIdforCertificate
s(Convert.ToInt32(returnValue));     
        return sw.ToString();;
    }
 


type 2:

 [WebMethod(true)]
  public static string WebMethod(string passedString)
 {
      string localString = passedString;       
        //System.Threading.Thread.
Sleep(5000);
    return localString;
 }

 function CallServerFun(assetid) {
         CallServer(assetid, '');
     }
     function CallServer(assetid, context) {
     }

     function ReceiveServerData(retValue) {
    alert(retValue);
     }
 

Calling server side function from Javascript

using _dopostback in asp.net without flickering page

 <script type="text/javascript">
function CallServerFunction()
{
__doPostBack('<%= upnlRes.UniqueID %>', '');
}
</script>

// in above example upnlRes is the UpdatePanel Id


__doPostBack is can load the page of asp.net.

ViewState Encryption in asp.net


Encrypting of the View State: You can enable view state encryption to make it more difficult for attackers and malicious users to directly read view state information. Though this adds processing overhead to the Web server, it supports in storing confidential information in view state. To configure view state encryption for an application does the following:

<Configuration>
         <system.web>
               <pages viewStateEncryptionMode="Always"/>
         </system.web>
</configuration>

Alternatively, you can enable view state encryption for a specific page by setting the value in the page directive, as the following sample demonstrates:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" ViewStateEncryptionMode="Always"%>

Cookies in asp.net



Response.Cookies["infn"]["visitDate"].Value = DateTime.Now.ToString(); 
Response.Cookies["infn"]["FName"].Value = "Tony";
Response.Cookies["infn"]["borderColor"].Value = "blue"; 
Response.Cookies["infn"].Expires = DateTime.Now.AddDays(1); 
 

Hide or Show validator callout control using javascript

Hide/Show validator callout control using javascript in asp.net

<script type="text/javascript">
function test()
{
$find("mpopup").hide();
}
</script>

Date format using Javascript


var today = new Date(); 
sDate = today.format("dd/MM/yyyy");
 
Protected by Copyscape Plagiarism Software