Thursday, June 19, 2014

check for nan javascript

The isNaN() function returns true if the value is NaN (Not-a-Number), and false if not.

var a = isNaN(123) + "<br>";
var b = isNaN(-1.23) + "<br>";
var c = isNaN(5-2) + "<br>";
var d = isNaN(0) + "<br>";
var e = isNaN("Hello") + "<br>";
var f = isNaN("2005/12/12") + "<br>";

false
false
false
false
true
true

how to remove read only attribute of textbox control through codebehind using asp.net

 txtusername.Attributes.Remove("readonly");

Wednesday, June 18, 2014

Get Data From datatable

DataTable dt = new DataTable();
            dt = _newleadspresenter.getAllLeaddata(LeadId);

string s = dt.rows[0].itemarray[0];

Read From Sqldatareader in asp.net

cmdstr = @"SELECT UserName, FirstName, MiddleName, LastName, Phone, Email, Profession, CategoryId, ReferredBy, LeadCategoryId, BirthDate, MaritalStatus, Note
                           FROM  Lead
                           WHERE (LeadId = " + LeadId + ")";
                myConnection.Open();
                SqlCommand cmd = new SqlCommand(cmdstr, myConnection);
                SqlDataReader reader = cmd.ExecuteReader();
                while (reader.Read())
                {

                    txtusername.Text = reader.GetString(0);                  

                    txtfirstname.Text = reader.GetString(1);

                    txtmiddlename.Text = reader.GetString(2);

                    txtlastname.Text = reader.GetString(3);

                    txtphone.Text = reader.GetString(4);

                    txtemail.Text = reader.GetString(5);

                    txtprofession.Text = reader.GetString(6);

                    ddlcategory.SelectedValue = reader.GetString(7);

                    ddlstatus.SelectedValue = reader.GetString(9);

                    txtbirthdate.Text = reader.GetString(10);

                    ddlmaritalstatus.SelectedValue = reader.GetString(11);

                    txtnote.Text = reader.GetString(12);

                }

                myConnection.Close();

            }

jquery check val is empty

if($('#person_data[document_type]').val() != ''){}

scriptmanager does not exist in the current context

add using System.Web.UI;

Tuesday, June 17, 2014

Common Session methods Use By Creating separate class

 //added by shekhar 13/6/2014 To Clear Current Session
        public void ClearSession()
        {
            HttpContext.Current.Session.Clear();
        }
        //End Of Clear Session
        //added by shekhar 13/6/2014 To Remove item in session
        public void RemoveFromSession(string key)
        {
            HttpContext.Current.Session.Remove(key);
        }
        //end Of remove  

        public void SetInSession(string key, object value)
        {
            if (HttpContext.Current == null || HttpContext.Current.Session == null)
            {
                return;
            }
            HttpContext.Current.Session[key] = value;
        }

        public object GetFromSession(string key)
        {
            if (HttpContext.Current == null || HttpContext.Current.Session == null)
            {
                return null;
            }
            return HttpContext.Current.Session[key];
        }

        public void UpdateInSession(string key, object value)
        {
            HttpContext.Current.Session[key] = value;
        }