Sunday, August 28, 2011

Fck editor Cs File , Fck Editor Dll alternative

using System ;
using System.Web.UI ;
using System.Web.UI.WebControls ;
using System.ComponentModel ;
using System.Text.RegularExpressions ;
using System.Globalization ;
using System.Security.Permissions ;

namespace External.FCKeditorAdaptor
{
    public enum LanguageDirection
    {
        LeftToRight,
        RightToLeft
    }

    [ DefaultProperty("Value") ]
    [ ValidationProperty("Value") ]
    [ ToolboxData("<{0}:FCKeditor runat=server></{0}:FCKeditor>") ]
    [ Designer("DotShoppingCart.OpenSource.External.FCKeditorAdaptor.FCKeditorDesigner") ]
    [ ParseChildren(false) ]
    public class FCKeditor : System.Web.UI.Control, IPostBackDataHandler
    {
        private bool _IsCompatible;

        public FCKeditor()
        {}

        #region Base Configurations Properties
       
        [ Browsable( false ) ]
        public FCKeditorConfigurations Config
        {
            get
            {
                if ( ViewState["Config"] == null )
                    ViewState["Config"] = new FCKeditorConfigurations() ;
                return (FCKeditorConfigurations)ViewState["Config"] ;
            }
        }

        [ DefaultValue( "" ) ]
        public string Value
        {
            get { object o = ViewState["Value"] ; return ( o == null ? "" : (string)o ) ; }
            set { ViewState["Value"] = value ; }
        }

        /// <summary>
        /// <p>
        ///        Sets or gets the virtual path to the editor's directory. It is
        ///        relative to the current page.
        /// </p>
        /// <p>
        ///        The default value is "/fckeditor/".
        /// </p>
        /// <p>
        ///        The base path can be also set in the Web.config file using the
        ///        appSettings section. Just set the "FCKeditor:BasePath" for that.
        ///        For example:
        ///        <code>
        ///        &lt;configuration&gt;
        ///            &lt;appSettings&gt;
        ///                &lt;add key="FCKeditor:BasePath" value="/scripts/fckeditor/" /&gt;
        ///            &lt;/appSettings&gt;
        ///        &lt;/configuration&gt;
        ///        </code>
        /// </p>
        /// </summary>
        [DefaultValue("/fckeditor/")]
        public string BasePath
        {
            get
            {
                object o = ViewState["BasePath"] ;

                if ( o == null )
                    o = System.Configuration.ConfigurationSettings.AppSettings["FCKeditor:BasePath"] ;

                return (o == null ? "/fckeditor/" : (string)o);
            }
            set { ViewState["BasePath"] = value ; }
        }

        [ DefaultValue( "Default" ) ]
        public string ToolbarSet
        {
            get { object o = ViewState["ToolbarSet"] ; return ( o == null ? "Default" : (string)o ) ; }
            set { ViewState["ToolbarSet"] = value ; }
        }

        #endregion

        #region Appearence Properties

        [ Category( "Appearence" ) ]
        [ DefaultValue( "100%" ) ]
        public Unit Width
        {
            get { object o = ViewState["Width"] ; return ( o == null ? Unit.Percentage(100) : (Unit)o ) ; }
            set { ViewState["Width"] = value ; }
        }

        [ Category("Appearence") ]
        [ DefaultValue( "200px" ) ]
        public Unit Height
        {
            get { object o = ViewState["Height"] ; return ( o == null ? Unit.Pixel( 200 ) : (Unit)o ) ; }
            set { ViewState["Height"] = value ; }
        }

        #endregion

        #region Configurations Properties

        [ Category("Configurations") ]
        public string CustomConfigurationsPath
        {
            set { this.Config["CustomConfigurationsPath"] = value ; }
        }

        [ Category("Configurations") ]
        public string EditorAreaCSS
        {
            set { this.Config["EditorAreaCSS"] = value ; }
        }

        [ Category("Configurations") ]
        public string BaseHref
        {
            set { this.Config["BaseHref"] = value ; }
        }

        [ Category("Configurations") ]
        public string SkinPath
        {
            set { this.Config["SkinPath"] = value ; }
        }

        [ Category("Configurations") ]
        public string PluginsPath
        {
            set { this.Config["PluginsPath"] = value ; }
        }

        [ Category("Configurations") ]
        public bool FullPage
        {
            set { this.Config["FullPage"] = ( value ? "true" : "false" ) ; }
        }

        [ Category("Configurations") ]
        public bool Debug
        {
            set { this.Config["Debug"] = ( value ? "true" : "false" ) ; }
        }

        [ Category("Configurations") ]
        public bool AutoDetectLanguage
        {
            set { this.Config["AutoDetectLanguage"] = ( value ? "true" : "false" ) ; }
        }

        [ Category("Configurations") ]
        public string DefaultLanguage
        {
            set { this.Config["DefaultLanguage"] = value ; }
        }

        [ Category("Configurations") ]
        public LanguageDirection ContentLangDirection
        {
            set { this.Config["ContentLangDirection"] = ( value == LanguageDirection.LeftToRight ? "ltr" : "rtl" )  ; }
        }

        [ Category("Configurations") ]
        public bool EnableXHTML
        {
            set { this.Config["EnableXHTML"] = ( value ? "true" : "false" ) ; }
        }

        [ Category("Configurations") ]
        public bool EnableSourceXHTML
        {
            set { this.Config["EnableSourceXHTML"] = ( value ? "true" : "false" ) ; }
        }

        [ Category("Configurations") ]
        public bool FillEmptyBlocks
        {
            set { this.Config["FillEmptyBlocks"] = ( value ? "true" : "false" ) ; }
        }

        [ Category("Configurations") ]
        public bool FormatSource
        {
            set { this.Config["FormatSource"] = ( value ? "true" : "false" ) ; }
        }

        [ Category("Configurations") ]
        public bool FormatOutput
        {
            set { this.Config["FormatOutput"] = ( value ? "true" : "false" ) ; }
        }

        [ Category("Configurations") ]
        public string FormatIndentator
        {
            set { this.Config["FormatIndentator"] = value ; }
        }

        [ Category("Configurations") ]
        public bool GeckoUseSPAN
        {
            set { this.Config["GeckoUseSPAN"] = ( value ? "true" : "false" ) ; }
        }

        [ Category("Configurations") ]
        public bool StartupFocus
        {
            set { this.Config["StartupFocus"] = ( value ? "true" : "false" ) ; }
        }

        [ Category("Configurations") ]
        public bool ForcePasteAsPlainText
        {
            set { this.Config["ForcePasteAsPlainText"] = ( value ? "true" : "false" ) ; }
        }

        [ Category("Configurations") ]
        public bool ForceSimpleAmpersand
        {
            set { this.Config["ForceSimpleAmpersand"] = ( value ? "true" : "false" ) ; }
        }

        [ Category("Configurations") ]
        public int TabSpaces
        {
            set { this.Config["TabSpaces"] = value.ToString( CultureInfo.InvariantCulture ) ; }
        }

        [ Category("Configurations") ]
        public bool UseBROnCarriageReturn
        {
            set { this.Config["UseBROnCarriageReturn"] = ( value ? "true" : "false" ) ; }
        }

        [ Category("Configurations") ]
        public bool ToolbarStartExpanded
        {
            set { this.Config["ToolbarStartExpanded"] = ( value ? "true" : "false" ) ; }
        }

        [ Category("Configurations") ]
        public bool ToolbarCanCollapse
        {
            set { this.Config["ToolbarCanCollapse"] = ( value ? "true" : "false" ) ; }
        }

        [ Category("Configurations") ]
        public string FontColors
        {
            set { this.Config["FontColors"] = value ; }
        }

        [ Category("Configurations") ]
        public string FontNames
        {
            set { this.Config["FontNames"] = value ; }
        }

        [ Category("Configurations") ]
        public string FontSizes
        {
            set { this.Config["FontSizes"] = value ; }
        }

        [ Category("Configurations") ]
        public string FontFormats
        {
            set { this.Config["FontFormats"] = value ; }
        }

        [ Category("Configurations") ]
        public string StylesXmlPath
        {
            set { this.Config["StylesXmlPath"] = value ; }
        }

        [ Category("Configurations") ]
        public string LinkBrowserURL
        {
            set { this.Config["LinkBrowserURL"] = value ; }
        }

        [ Category("Configurations") ]
        public string ImageBrowserURL
        {
            set { this.Config["ImageBrowserURL"] = value ; }
        }

        [Category("Configurations")]
        public bool HtmlEncodeOutput
        {
            set { this.Config["HtmlEncodeOutput"] = (value ? "true" : "false"); }
        }

        #endregion

        #region Rendering

        public string CreateHtml()
        {
            System.IO.StringWriter strWriter = new System.IO.StringWriter();
            System.Web.UI.HtmlTextWriter writer = new HtmlTextWriter(strWriter);
            this.Render(writer);
            return strWriter.ToString();
        }

        protected override void Render(HtmlTextWriter writer)
        {
            writer.Write( "<div>" ) ;

            if (_IsCompatible)
            {
                string sLink = this.BasePath ;
                if ( sLink.StartsWith( "~" ) )
                    sLink = this.ResolveUrl( sLink ) ;

                string sFile =
                    System.Web.HttpContext.Current.Request.QueryString["fcksource"] == "true" ?
                        "fckeditor.original.html" :
                        "fckeditor.html" ;

                sLink += "editor/" + sFile + "?InstanceName=" + this.ClientID ;
                if ( this.ToolbarSet.Length > 0 ) sLink += "&amp;Toolbar=" + this.ToolbarSet ;

                // Render the linked hidden field.
                writer.Write(
                    "<input type=\"hidden\" id=\"{0}\" name=\"{1}\" value=\"{2}\" />",
                        this.ClientID,
                        this.UniqueID,
                        System.Web.HttpUtility.HtmlEncode( this.Value ) ) ;

                // Render the configurations hidden field.
                writer.Write(
                    "<input type=\"hidden\" id=\"{0}___Config\" value=\"{1}\" />",
                        this.ClientID,
                        this.Config.GetHiddenFieldString() ) ;

                // Render the editor IFRAME.
                writer.Write(
                    "<iframe id=\"{0}___Frame\" src=\"{1}\" class=\"fckeditorTextArea\" width=\"{2}\" height=\"{3}\" frameborder=\"no\" scrolling=\"no\"></iframe>",
                        this.ClientID,
                        sLink,
                        this.Width,
                        this.Height ) ;
            }
            else
            {
                writer.Write(
                    "<textarea name=\"{0}\" class=\"fckeditorTextArea\" rows=\"4\" cols=\"40\" style=\"width: {1}; height: {2}\" wrap=\"virtual\">{3}</textarea>",
                        this.UniqueID,
                        this.Width,
                        this.Height,
                        System.Web.HttpUtility.HtmlEncode( this.Value ) ) ;
            }

            writer.Write( "</div>" ) ;
        }

        protected override void OnPreRender( EventArgs e )
        {
            base.OnPreRender( e );
           
            _IsCompatible = this.CheckBrowserCompatibility();

            if ( !_IsCompatible )
                return;

            object oScriptManager = null;

            // Search for the ScriptManager control in the page.
            Control oParent = this.Parent;
            while ( oParent != null )
            {
                foreach ( object control in oParent.Controls )
                {
                    // Match by type name.
                    if ( control.GetType().FullName == "System.Web.UI.ScriptManager" )
                    {
                        oScriptManager = control;
                        break;
                    }
                }

                if ( oScriptManager != null )
                    break;

                oParent = oParent.Parent;
            }

            // If the ScriptManager control is available.
            if ( oScriptManager != null )
            {
                try
                {
                    // Use reflection to check the SupportsPartialRendering
                    // property value.
                    bool bSupportsPartialRendering = ((bool)(oScriptManager.GetType().GetProperty( "SupportsPartialRendering" ).GetValue( oScriptManager, null )));

                    if ( bSupportsPartialRendering )
                    {
                        string sScript = "(function()\n{\n" +
                            "\tvar editor = FCKeditorAPI.GetInstance('" + this.ClientID + "');\n" +
                            "\tif (editor)\n" +
                            "\t\teditor.UpdateLinkedField();\n" +
                            "})();\n";

                        // Call the RegisterOnSubmitStatement method through
                        // reflection.
                        oScriptManager.GetType().GetMethod( "RegisterOnSubmitStatement", new Type[] { typeof( Control ), typeof( Type ), typeof( String ), typeof( String ) } ).Invoke( oScriptManager, new object[] {
                            this,
                            this.GetType(),
                            "FCKeditorAjaxOnSubmit_" + this.ClientID,
                            sScript } );

                        // Tell the editor that we are handling the submit.
                        this.Config[ "PreventSubmitHandler" ] = "true";
                    }
                }
                catch { }
            }
        }

        #endregion

        #region Compatibility Check

        public bool CheckBrowserCompatibility()
        {
            return IsCompatibleBrowser();
        }

        /// <summary>
        /// Checks if the current HTTP request comes from a browser compatible
        /// with FCKeditor.
        /// </summary>
        /// <returns>"true" if the browser is compatible.</returns>
        public static bool IsCompatibleBrowser()
        {
            return IsCompatibleBrowser( System.Web.HttpContext.Current.Request );
        }

        /// <summary>
        /// Checks if the provided HttpRequest object comes from a browser
        /// compatible with FCKeditor.
        /// </summary>
        /// <returns>"true" if the browser is compatible.</returns>
        public static bool IsCompatibleBrowser( System.Web.HttpRequest request )
        {
            System.Web.HttpBrowserCapabilities oBrowser = request.Browser;

            // Internet Explorer 5.5+ for Windows
            if ( oBrowser.Browser == "IE" && ( oBrowser.MajorVersion >= 6 || ( oBrowser.MajorVersion == 5 && oBrowser.MinorVersion >= 0.5 ) ) && oBrowser.Win32 )
                return true;

            string sUserAgent = request.UserAgent;

            if ( sUserAgent.IndexOf( "Gecko/" ) >= 0 )
            {
                Match oMatch = Regex.Match( request.UserAgent, @"(?<=Gecko/)\d{8}" );
                return ( oMatch.Success && int.Parse( oMatch.Value, CultureInfo.InvariantCulture ) >= 20030210 );
            }

            if ( sUserAgent.IndexOf( "Opera/" ) >= 0 )
            {
                Match oMatch = Regex.Match( request.UserAgent, @"(?<=Opera/)[\d\.]+" );
                return ( oMatch.Success && float.Parse( oMatch.Value, CultureInfo.InvariantCulture ) >= 9.5 );
            }

            if ( sUserAgent.IndexOf( "AppleWebKit/" ) >= 0 )
            {
                Match oMatch = Regex.Match( request.UserAgent, @"(?<=AppleWebKit/)\d+" );
                return ( oMatch.Success && int.Parse( oMatch.Value, CultureInfo.InvariantCulture ) >= 522 );
            }

            return false;
        }

        #endregion

        #region Postback Handling

        public bool LoadPostData(string postDataKey, System.Collections.Specialized.NameValueCollection postCollection)
        {
            string postedValue = postCollection[postDataKey] ;

            // Revert the HtmlEncodeOutput changes.
            if ( this.Config["HtmlEncodeOutput"] != "false" )
            {
                postedValue = postedValue.Replace( "&lt;", "<" ) ;
                postedValue = postedValue.Replace( "&gt;", ">" ) ;
                postedValue = postedValue.Replace( "&amp;", "&" ) ;
            }

            if ( postedValue != this.Value )
            {
                this.Value = postedValue ;
                return true ;
            }
            return false ;
        }

        public void RaisePostDataChangedEvent()
        {
            // Do nothing
        }

        #endregion
    }
}

Dynamic Metatag In asp.net c# , Dynamic metatag in master Page

In Master Page :

<%@ Master Language="C#" AutoEventWireup="true" CodeFile="MasterPage.master.cs" Inherits="MasterPage" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
<title id="PageTitle" runat="server">This is the Default Page Title...</title>
<meta name="Keywords" id="PageKeywords" content="default, page, keywords" runat="server" />
<meta name="Description" id="PageDescription" content="This is the Default page desctription, which should be changed when the page is loaded." runat="server" /> 


 In Master Page .cs file :

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class MasterPage : System.Web.UI.MasterPage
{
    protected void Page_Load(object sender, EventArgs e)
    {
   
    }

    public string MetaTitle
    {
        get
        {
            return PageTitle.Text;
        }
        set
        {
            PageTitle.Text = value;
        }
    }
    public string MetaKeywords
    {
        get
        {
            return PageKeywords.Content;
        }
        set
        {
            PageKeywords.Content = value;
        }
    }
    public string MetaDescription
    {
        get
        {
            return PageDescription.Content;
        }
        set
        {
            PageDescription.Content = value;
        }
    }
}
 

Default.aspx.cs Page :
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        MasterPage myMaster = (MasterPage)this.Master;
        myMaster.MetaTitle = "This is the new Page Title, which is set upon Page_Load";
        myMaster.MetaDescription = "Hitendra";
        myMaster.MetaKeywords = "new, page, keywords, set, upon, page, load";
    }
}
 

Tuesday, August 23, 2011

Dynamic Metatag In Master Page

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        MasterPage myMaster = (MasterPage)this.Master;
        myMaster.MetaTitle = "This is the new Page Title, which is set upon Page_Load";
        myMaster.MetaDescription = "Hitendra";
        myMaster.MetaKeywords = "new, page, keywords, set, upon, page, load";
    }
}





head id="Head1" runat="server">
title id="PageTitle" runat="server">This is the Default Page Title...</title>
meta name="Keywords" id="PageKeywords" content="default, page, keywords" runat="server" />
meta name="Description" id="PageDescription" content="This is the Default page desctription, which should be changed when the page is loaded." runat="server" />

Sample Application On 3 -tier Architecture in asp.net c#

BLL.cs

using System;
using System.Collections.Generic;

using System.Web;


namespace _3_tier_Sample
{
    public class BLL
    {

        public string InsertUserDetails(Class1 objUserDetails)
        {
            DAL objUserDAL = new DAL();
            try
            {
                return objUserDAL.InsertUserInformation(objUserDetails);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                objUserDAL = null;
            }
        }

    }
}
  

Class1.cs 

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

namespace _3_tier_Sample
{
    public class Class1
    {
        #region Variables
        /// <summary>
        /// User Registration Variables
        /// </summary>
       
        private string _FirstName;
        private string _LastName;
        private string _Email;
        #endregion
        public string FirstName
        {
            get
            {
                return _FirstName;

            }
            set
            {
                _FirstName = value;
            }
        }

        public string LastName
        {
            get
            {
                return _LastName;

            }
            set
            {
                _LastName = value;
            }
        }


        public string Email
        {
            get
            {
                return _Email;
            }
            set
            {
                _Email = value;
            }
        }

    }
   

}





DAl.cs

using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;

using System.Web;

namespace _3_tier_Sample
{
    public class DAL
    {
        //SQL Connection string
        string ConnectionString = ConfigurationManager.AppSettings["LocalConnection"].ToString();

        #region Insert User Details
        /// <summary>
        /// Insert Job Details
        /// </summary>
        /// <param name="objBELJobs"></param>
        /// <returns></returns>
        public string InsertUserInformation(Class1 objBELUserDetails)
        {
            SqlConnection con = new SqlConnection(ConnectionString);
            con.Open();
            SqlCommand cmd = new SqlCommand("sp_userinformation", con);
            cmd.CommandType = CommandType.StoredProcedure;
            try
            {
               
                cmd.Parameters.AddWithValue("@FirstName", objBELUserDetails.FirstName);
                cmd.Parameters.AddWithValue("@LastName", objBELUserDetails.LastName);
                cmd.Parameters.AddWithValue("@Email", objBELUserDetails.Email);
                cmd.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                cmd.Dispose();
                con.Close();
                con.Dispose();
            }
        }
        #endregion
    }
}



Default.aspx.cs

using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace _3_tier_Sample
{
    public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }
        protected void btnsubmit_Click(object sender, EventArgs e)
        {
            string output = string.Empty;
            Class1 objClass  = new Class1();
            objClass.FirstName = txtfname.Text;
            objClass.LastName = txtlname.Text;
            objClass.Email = txtEmail.Text;
            BLL objBLL = new BLL();
            output = objBLL.
        }
    }
}

 

Tuesday, August 9, 2011

Remove Default Empty Column From DataGrid

Remove Default Empty Column From DataGrid. you can see the extra default column when you bind the data grid control. Sometime it is required to remove that extra empty column.

      There are two situation when you are binding the datagrid control.

  1. AutoGenerateColumns is set to False
  2. AutoGenerateColumns is set to True
When you set the AutoGenerateColumns to false then you can set the columns by using either DataGridTextColumn, DataGridCheckBoxColumn or DataGridTemplateColumn, in this case you know the last column of the datagrid and what you have to do is to set the width of last column to (*). When you have AutoGenerateColumns to false, the code is shown in the List 1. here you can see that I have set the width of the last column which is the address column is set to (*).
 
 

 

TicTacToe Game

MAke Tac Toe Game in Asp.net  C#


Simple Asp.net C# Game


How to make Asp.net c# Game


Download Game