الجمعة، 30 ديسمبر 2011

Write Simple LINQ TO SQL To Calling Stored Procedure Without ORM Tool

namespace LINQTOSQLFromScraTCH
{
    public class SP_GetAllCustomersResult
    {

        private int _CID;

        private string _CName;

        private string _CPassword;

        [Column(Storage = "_CID", DbType = "Int NOT NULL")]
        public int CID
        {
            get
            {
                return this._CID;
            }
            set
            {
                this._CID = value;
            }
        }

        [Column(Storage = "_CName", DbType = "VarChar(50)")]
        public string CName
        {
            get
            {
                return this._CName;
            }
            set
            {
                this._CName = value;
            }
        }

        [Column(Storage = "_CPassword", DbType = "VarChar(50)")]
        public string CPassword
        {
            get
            {
                return this._CPassword;
            }
            set
            {
                this._CPassword = value;
            }
        }
    }

    [Database(Name = "Lab5")]
    public class clsMyContext : DataContext
    {
        public clsMyContext(string connection) : base(connection)
        {
           
        }

        [FunctionAttribute(Name="dbo.SP_GetAllCustomers")]
        public ISingleResult SP_GetAllCustomers()
        {
            IExecuteResult result = this.ExecuteMethodCall(this, ((MethodInfo)(MethodInfo.GetCurrentMethod())));
            return ((ISingleResult)(result.ReturnValue));
        }
    }
}


---------------

Calling

static void Main(string[] args)
        {
            clsMyContext context = new clsMyContext(@"Data Source=.\sqlexpress;Initial Catalog=Lab5;Integrated Security=True");

            var MyQuery = context.SP_GetAllCustomers();

            foreach (var item in MyQuery)
            {
                Console.WriteLine(item.CName);
            }
        }

الأربعاء، 21 ديسمبر 2011

Understand ASP.NET Profile with example




Configure web.config file as the following




Code in first page (Default.aspx)
  protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
            Label1.Text = Profile.FullName;
    }
    protected void Page_PreInit(object sender, EventArgs e)
    {
        Page.Theme = Profile.MyTheme;
    }


Code in Second page (Setting.aspx)
   protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            Label1.Text = Profile.FullName;
            //this command make update to themes to change color to not store the old values.
            DropDownList1.Items.FindByValue(Profile.MyTheme).Selected = true;
        }
    }
    protected void btnSaveProfile_Click(object sender, EventArgs e)
    {
        Profile.FullName = TextBox1.Text;
        Profile.MyTheme = DropDownList1.SelectedValue;
        Response.Redirect("~/Default.aspx");
    }

الاثنين، 19 ديسمبر 2011

How to access Control With javaScrip

How to access Control With javaScrip

Sample from MSDN

<%@ Control AutoEventWireup="true" %>













الخميس، 8 ديسمبر 2011

LigthSwitch 2011 Arabic Demo

الأربعاء، 7 ديسمبر 2011

Simple Trick to check if Javascript supported in Client Browser using ASPX


protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["JSChecked"] == null)    //JSChecked -indicates if it tried to run the JavaScript version
        {
            Session["JSChecked"] = "Checked";
            string path = Request.Url + "?JScript=1";
            Page.ClientScript.RegisterStartupScript(this.GetType(), "redirect", "window.location.href='" + path + "';", true);
        }
        if (Request.QueryString["JScript"] == null)
            Response.Write("JavaScript is not enabled.");
        else
            Response.Write("JavaScript is enabled.");
    }

الأربعاء، 30 نوفمبر 2011

Clear all combox controls expect those in Array

الثلاثاء، 29 نوفمبر 2011

Branding ASP.NET Web Application

الاثنين، 28 نوفمبر 2011

Clear all Controls inside Container using Recursive techniques

 
   private void btnClear_Click(object sender, EventArgs e)
        {
            ClearControls(this);
        }

        private void ClearControls(Control c)
        {
            foreach (Control ctrl in c.Controls)
            {
                if (ctrl is TextBox)
                {
                    ctrl.Text = "";
                }

                else
                {
                    if (ctrl.Controls.Count > 0)
                    {
                        ClearControls(ctrl);
                    }

                }

            }
        }