Sunday 28 April 2013

ajax asyncfileupload textbox after file upload in asp.net


Design Code:<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>

<!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 runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <asp:ScriptManager ID="sm" runat="server"></asp:ScriptManager>
    <div>
 
    <table align="center">
    <tr><td>Upload</td><td>
        <asp:AsyncFileUpload ID="fileUpload1" runat="server" OnUploadedComplete="fileUploadComplete" /><br /><asp:Label ID="lb" runat="server"></asp:Label>
    </td></tr>
    <tr><td><asp:CheckBox ID="cb" runat="server" AutoPostBack="true"
            oncheckedchanged="cb_CheckedChanged" />Press Me</td><td>
      <asp:Button  ID="btn" runat="server" Text="Save" onclick="btn_Click" />
    </td></tr>
    </table>
  
    </div>
    </form>
</body>
</html>
C# code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using AjaxControlToolkit;
using System.Threading;

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

    }
    protected void btn_Click(object sender, EventArgs e)
    {
        lb.Text = Application["x"].ToString();
    }
    protected void fileUploadComplete(object sender, AsyncFileUploadEventArgs e)
    {
       Thread.Sleep(1000);
        string filename = System.IO.Path.GetFileName(fileUpload1.FileName);
        Application["x"] = filename;
        fileUpload1.SaveAs(Server.MapPath("image/") + filename);
      
     

    }

    protected void cb_CheckedChanged(object sender, EventArgs e)
    {
       
    }
}

Friday 26 April 2013

jQuery Uploading Multiple Files using Asp.net with Uploadify Plugin

how to desable of browser back button

<head>
<script type="text/javascript">
        window.history.forward();
        function noBack() {
            window.history.forward();
        }
    </script>
</head>
<body onload="noBack();" onpageshow="if (event.persisted) noBack();" onunload="">

Wednesday 24 April 2013

login page

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Login.aspx.cs" Inherits="Website.ERP.ADMIN.Login" %>

<!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 runat="server">
    <title></title>
    <link href="../../css/ken-campus-main.css" rel="stylesheet" type="text/css" />
        <style type="text/css">
    .Maintitle
        {
            text-align: left;
            width: 100%;
            display: block;
            font-family: Arial;
            float: left;
            height: 19px;
            color: #014483;
            font-size: 15px;
            font-weight: normal;
        }
        .MainTitleSeparator
        {
            padding-bottom: 1px;
            width: 100%;
            float: left;
            height: 1px;
            background-color: #9ec1ee;
            border-top: #9ec1ee 1px solid;
            margin-bottom: 10px;
        }
        .grid
        {
            width: 99.7%;
            height: auto;
            border: solid 2px #c8c8c8;
            float: left;
        }
        .grid_top
        {
            behavior: url(~/css/PIE.htc);
            border-top-left-radius: 10px;
            border-top-right-radius: 10px;
            width: 99%;
            height: auto;
            border: solid 4px #c8c8c8;
            float: left;
            background-color: #c8c8c8;
            -moz-border-radius-topleft: 10px;
            -webkit-border-top-left-radius: 10px;
            -khtml-border-radius-topleft: 10px;
            -moz-border-radius-topright: 10px;
            -webkit-border-top-right-radius: 10px;
            -khtml-border-radius-topright: 10px;
        }
        .AddNew
        {
            text-align: right;
            display: block;
            float: right;
            height: auto;
            color: #333333;
            text-decoration: none;
        }
        .DefaultWOITest
        {
            border-bottom: #888 1px solid;
            border-left: #888 1px solid;
            padding-bottom: 1%;
            margin: 1.8% 0px 0px;
            padding-left: 1%;
            width: 98%;
            padding-right: 1%; /*background: #e5e5e5;*/
            background: white;
            float: left;
            height: auto;
            font-size: 12px;
            border-top: #888 1px solid;
            font-weight: normal;
            border-right: #888 1px solid;
            padding-top: 1%;
        }
        .PlaceButtonInv
        {
            text-align: right;
            padding-bottom: 5px;
            padding-right: 5px;
            padding-top: 5px;
            padding-left: 5px;
            width: 98%;
            display: block;
            float: left;
            height: auto;
        }
        .PlaceButtonInv INPUT
        {
            background-color: #c8c8c8;
            font-family: Calibri;
            font-size: 12px;
            font-weight: bold;
            width: auto;
            height: 20px;
            padding-left: 10px;
            padding-right: 10px;
            padding-top: 1px;
            padding-bottom: 3px;
            text-align: center;
            color: #666;
            border: solid 1.5px #9ec1ee;
            border-radius: 3px;
            -moz-border-radius: 3px;
        }
        .m
        {
            border-radius: 10px;
            -moz-border-radius: 10px;
            width:400px;
             height:200px;
              top:200px;
              position:relative;
                border: solid 1.5px #9ec1ee;
        }
    </style>
    <script src="../../Scripts/jquery-1.8.2.js" type="text/javascript"></script>
    <script language="javascript" type="text/javascript">
        $(document).ready
    (
    function () {
        $('#<%=txtname.ClientID %>').focus();
        $('#<%=btnsave.ClientID %>').live("click", function () {
            if ($('#<%=txtname.ClientID %>').val() == "") {
                alert('User name should not blank.');
                $('#<%=txtname.ClientID %>').focus();
                return false;

            }
            else if ($('#<%=txtpass.ClientID %>').val() == "") {
                alert('Password should not blank.');
                $('#<%=txtpass.ClientID %>').focus();
                return false;
            }
        });

        $('#<%=btnreset.ClientID %>').live("click", function () {
            $('#<%=txtname.ClientID %>').val('');
            $('#<%=txtpass.ClientID %>').val('');
            $('#<%=txtname.ClientID %>').focus();
            return false;
        });
    }
    )
    </script>

</head>
<body>
    <form id="form1" runat="server">
    <asp:ScriptManager ID="sm" runat="server"></asp:ScriptManager>
    <asp:UpdatePanel ID="up" runat="server">
    <ContentTemplate>
    <center>
     <div class="m">
    <div class="Maintitle">&nbsp;Login</div>
    <div class="MainTitleSeparator">
    </div>
    <br />
     <br />
    <br />
     <br />
   
    <div class="labeldiv">User Name:</div>
    <div class="valuedivSmall"><asp:TextBox ID="txtname" runat="server" Width="200"></asp:TextBox><span style="color:Red">*</span></div>
    <div class="labeldiv">Password:</div>
    <div class="valuedivSmall"><asp:TextBox ID="txtpass" TextMode="Password" runat="server" Width="150"></asp:TextBox><span style="color:Red">*</span></div>
  
     <div class="PlaceButtonInv">
                            <asp:Button ID="btnsave" runat="server" Text="Submit" Width="80"  />&nbsp;<asp:Button
                                ID="btnreset" runat="server" Text="Reset" Width="80"  /></div>
                    </div>
    </center>
  
    </div>

    </ContentTemplate>
    </asp:UpdatePanel>
 
    </form>
</body>
</html>

Tuesday 23 April 2013

how to dynamic node populate in treeview with checkbox in c#.net



Procedure
ALTER PROCEDURE dbo.p
AS
    begin
    select m.eid,m.name,m.mgr,(select count(*) from emp where emp.mgr=m.eid) ccount from emp m left join emp t on m.mgr=t.eid
    end
    page looks like:



c# code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication33
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        DataClasses1DataContext o = new DataClasses1DataContext();
        private void Form1_Load(object sender, EventArgs e)
        {
            fillcombox();
            filltv();
        }
        void fillcombox()
        {
            var m = (from x in o.EMP4s select new { x.EID, x.NAME }).ToList();
            comboBox1.DataSource = m;
            comboBox1.DisplayMember = "NAME";
            comboBox1.ValueMember = "EID";
        }
        void filltv()
        {
            treeView1.Nodes.Clear();
            var m = (from x in o.EMP4s where x.MGR==0 select new { x.EID, x.NAME }).ToList();
            for (int i = 0; i < m.Count; i++)
            {
                TreeNode tn = new TreeNode();
               
                tn = treeView1.Nodes.Add(m[i].EID.ToString(), m[i].NAME,m[i].EID);
                filltv1(m[i].EID, tn);
            }
        }
        void filltv1(int id, TreeNode tn1)
        {
            var m = (from x in o.EMP4s where x.MGR == id select new { x.EID, x.NAME }).ToList();
            for(int j=0;j<m.Count;j++)
            {
                TreeNode tn2 = new TreeNode();
                if (tn1 == null)
                    tn2 = treeView1.Nodes.Add(m[j].EID.ToString(), m[j].NAME,m[j].EID);
                else
                    tn2 = tn1.Nodes.Add(m[j].EID.ToString(), m[j].NAME);
                filltv1(m[j].EID, tn2);
            }
        }
        private void button1_Click(object sender, EventArgs e)
        {
            EMP4 p = new EMP4();
            p.EID = Convert.ToInt32(textBox1.Text);
            p.NAME = textBox2.Text;
            p.MGR = Convert.ToInt32(comboBox1.SelectedValue.ToString());
            o.EMP4s.InsertOnSubmit(p);
            o.SubmitChanges();
            fillcombox();
            filltv();
        }

        private void treeView1_AfterCheck(object sender, TreeViewEventArgs e)
        {
            if (e.Node.Checked)
                foreach (TreeNode tn in e.Node.Nodes)
                    tn.Checked = true;
            else
                foreach (TreeNode tn in e.Node.Nodes)
                    tn.Checked = false;

        }

        private void button2_Click(object sender, EventArgs e)
        {
            foreach (TreeNode tn in treeView1.Nodes)
                MessageBox.Show(tn.ImageIndex.ToString());
        }

       
    }
}
 

how to dynamic node populate in treeview with checkbox in asp.net








Procedure
ALTER PROCEDURE dbo.p
AS
    begin
    select m.eid,m.name,m.mgr,(select count(*) from emp where emp.mgr=m.eid) ccount from emp m left join emp t on m.mgr=t.eid
    end
   
design code:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!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 runat="server">
    <title></title>
        <script language="javascript" type="text/javascript">
            function OnTreeClick(evt) {
                var src = window.event != window.undefined ? window.event.srcElement : evt.target;
                var isChkBoxClick = (src.tagName.toLowerCase() == "input" && src.type == "checkbox");
                if (isChkBoxClick) {
                    //alert(src.value);
                    var parentTable = GetParentByTagName("table", src);
                    var nxtSibling = parentTable.nextSibling;
                    //check if nxt sibling is not null & is an element node
                    if (nxtSibling && nxtSibling.nodeType == 1) {
                        if (nxtSibling.tagName.toLowerCase() == "div")
                        //if node has children
                        {
                            //check or uncheck children at all levels
                            CheckUncheckChildren(parentTable.nextSibling, src.checked);
                        }
                    }
                    //check or uncheck parents at all levels
                    CheckUncheckParents(src, src.checked);
                }
            }
            function CheckUncheckChildren(childContainer, check) {
                var childChkBoxes = childContainer.getElementsByTagName("input");
                var childChkBoxCount = childChkBoxes.length;
                for (var i = 0; i < childChkBoxCount; i++) {
                    childChkBoxes[i].checked = check;
                }
            }

            function CheckUncheckParents(srcChild, check) {
                var parentDiv = GetParentByTagName("div", srcChild);
                var parentNodeTable = parentDiv.previousSibling;
                if (parentNodeTable) {
                    var checkUncheckSwitch;
                    if (check) //checkbox checked
                    {
                        var isAllSiblingsChecked = AreAllSiblingsChecked(srcChild);
                        if (isAllSiblingsChecked)
                            checkUncheckSwitch = true;
                        else
                            return; //do not need to check parent if any(one or more) child not checked
                    }
                    else //checkbox unchecked
                    {
                        checkUncheckSwitch = false;
                    }
                    var inpElemsInParentTable = parentNodeTable.getElementsByTagName("input");
                    if (inpElemsInParentTable.length > 0) {
                        var parentNodeChkBox = inpElemsInParentTable[0];
                        parentNodeChkBox.checked = checkUncheckSwitch; //do the same recursively
                        CheckUncheckParents(parentNodeChkBox, checkUncheckSwitch);
                    }
                }
            }

            function AreAllSiblingsChecked(chkBox) {
                var parentDiv = GetParentByTagName("div", chkBox);
                var childCount = parentDiv.childNodes.length;
                for (var i = 0; i < childCount; i++) {
                    if (parentDiv.childNodes[i].nodeType == 1) {
                        //check if the child node is an element node
                        if (parentDiv.childNodes[i].tagName.toLowerCase() == "table") {
                            var prevChkBox = parentDiv.childNodes[i].getElementsByTagName("input")[0];
                            //if any of sibling nodes are not checked,
                            return false
                            if (!prevChkBox.checked) {
                                return false;
                            }
                        }
                    }
                }
                return true;
            }
            //utility function to get the container of an element by tagname
            function GetParentByTagName(parentTagName, childElementObj) {
                var parent = childElementObj.parentNode;
                while (parent.tagName.toLowerCase() != parentTagName.toLowerCase()) {
                    parent = parent.parentNode;
                }
                return parent;
            }

    </script>
</head>
<body>
        <form id="form1" runat="server">
    <asp:ScriptManager ID="sm" runat="server"></asp:ScriptManager>
    <asp:UpdatePanel ID="up" runat="server">
    <ContentTemplate>
    <div>
    <table align="center">
    <tr><td>EID</td><td><asp:TextBox ID="tb" runat="server"></asp:TextBox></td></tr>
    <tr><td>NAME</td><td><asp:TextBox ID="tb1" runat="server"></asp:TextBox></td></tr>
     <tr><td>MGR</td><td><asp:DropDownList ID="ddl" runat="server"></asp:DropDownList></td></tr>
      <tr><td>&nbsp;</td><td><asp:Button ID="btn" runat="server" Text="Save" Width="80"
              onclick="btn_Click"/></td></tr>
      <tr><td>&nbsp;</td><td><asp:TreeView ID="tv" runat="server" ShowCheckBoxes="All"
              ontreenodepopulate="tv_TreeNodePopulate"></asp:TreeView></td></tr>
    </table>
    </div>
    </ContentTemplate>
    </asp:UpdatePanel>
 
    </form>

</body>
</html>
c# code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class _Default : System.Web.UI.Page
{
    #region
    DataClassesDataContext o = new DataClassesDataContext();
    #endregion
    protected void Page_Load(object sender, EventArgs e)
    {
        tv.Attributes.Add("onclick", "OnTreeClick(event)");
        if (!IsPostBack)
        {
            fill();
            filltv();
            tv.CollapseAll();
        }
    }
    void fill()
    {
        var m = (from x in o.EMPs select new {x.EID,x.NAME}).ToList();
        ddl.DataSource = m;
        ddl.DataTextField = "NAME";
        ddl.DataValueField = "EID";
        ddl.DataBind();
    }
    void filltv()
    {
        tv.Nodes.Clear();
        var m=(from x in o.p() where x.mgr==0 select  new {x.eid,x.name,x.ccount}).ToList();

        for (int i = 0; i < m.Count; i++)
        {
            TreeNode tn = new TreeNode();
            tn.Text = m[i].name;
            tn.Value = m[i].eid.ToString();
            tv.Nodes.Add(tn);
            tn.PopulateOnDemand = false;
            if (m[i].ccount > 0)
                tn.PopulateOnDemand = true;
        }
    }
    protected void btn_Click(object sender, EventArgs e)
    {
        EMP p = new EMP();
        p.EID = Convert.ToInt32(tb.Text);
        p.NAME = tb1.Text;
        p.MGR = Convert.ToInt32(ddl.SelectedValue);
        o.EMPs.InsertOnSubmit(p);
        o.SubmitChanges();
        ScriptManager.RegisterClientScriptBlock(this, GetType(), "x", "alert('One record saved.')", true);
        fill();
        filltv();
    }
    protected void tv_TreeNodePopulate(object sender, TreeNodeEventArgs e)
    {
        var m = (from x in o.p() where x.mgr == Convert.ToInt32(e.Node.Value) select new {x.eid,x.name,x.ccount }).ToList();
        for(int i=0;i<m.Count;i++)
        {
        TreeNode tn = new TreeNode();
        tn.Value = m[i].eid.ToString();
        tn.Text = m[i].name;
        e.Node.ChildNodes.Add(tn);
        tn.PopulateOnDemand = false;
        if (m[i].ccount > 0)
            tn.PopulateOnDemand = true;
        }
    }
}