Wednesday, 2 April 2014

Reading session value from jquery using WebHandler

using System;
using System.Web;
using System.Web.SessionState;
using System.Web.Script.Serialization;

public class ReadSession : IHttpHandler,IReadOnlySessionState
{
    public void ProcessRequest(HttpContext context)
    {
        context.Response.ContentType = "application/json";
        context.Response.Write(new JavaScriptSerializer().Serialize(new
        {
            Key = context.Request["key"],
            Value = (context.Session[context.Request["key"]]!=null && context.Session[context.Request["key"]]!="" ? context.Session[context.Request["key"]]:"")
        }));
    }

    public bool IsReusable
    {
        get { return true; }
    }
}


/*-------( In jquery just call like this )--------*/


 $.getJSON('/ReadSession.ashx', { key: key }, function (result) {
        alert(result.Value);
    });

Tuesday, 25 March 2014

Confirm message box in jquery

  if (confirm("Do you want to delete this record!")) {alert('you clicked on OK button')}
else{alert('you clicked on CANCEL button')}

Monday, 10 March 2014

create cookies using javascript

/*-----( CREATING COOKIE )------*/

 var email =$('#txtUserName').val();
 var pwd = $('#txtPassword').val();
 var d = new Date();
    d.setTime(d.getTime()+(30*24*60*60*1000));
     var v_rememberMe = $('#RememberMe').is(':checked') == true ? "Y":"N";
    $('#RememberMe').is(':checked') == true ? (document.cookie = "email=" + email + ";expires=" + d.toGMTString() + "") : d.setTime(d.getTime() + (-31 * 24 * 60 * 60 * 1000)); document.cookie = "email=" + email + ";expires=" + d.toGMTString() + "";

/*-------( GETTING COOKIE VALUES )--------*/
$(document).ready(function () {

    var mail = getCookie("email");
    var expdays = getCookie("expires");
 
   // mail!= "" ? ($('#txtPassword').focus(); $('#txtUserName').val(mail)): $('#txtUserName').focus();
    if (mail != "") {
        $('#txtPassword').focus(); $('#txtUserName').val(mail); $('#RememberMe').attr('checked', true);
    }
    else { $('#txtUserName').focus(); }
});
/*----( Getting cookie by Name )----*/
function getCookie(cname) {
    var name = cname + "=";
    var ca = document.cookie.split(';');
    for (var i = 0; i < ca.length; i++) {
        var c = ca[i].trim();
        if (c.indexOf(name) == 0) return c.substring(name.length, c.length);
    }
    return "";
}

Sunday, 9 March 2014

set checkbox list selection based on the DB values

  try
            {
string DBVal="1,2,3,";
                if (DBVal != "")
                {
                    string[] str = DBVal.Split(',');
                    foreach (var i in str)
                    {
                        ChkBoxList.Items.FindByValue(i).Selected = true;
                    }
                }
            }
            catch { }

getting checked list box values in asp.net

HERE WE CAN SEPERATE WITH ","

 var selected = ChkBoxList.Items.Cast<ListItem>().Where(x => x.Selected);
            foreach (var chkItem in selected)
            {
                string str += chkItem.Value + ",";
            }

Tuesday, 25 February 2014

Don’t run production ASP.NET Applications with debug=”true” enabled

One of the things you want to avoid when deploying an ASP.NET application into production is to accidentally (or deliberately) leave the <compilation debug=”true”/> switch on within the application’s web.config file.


Doing so causes a number of non-optimal things to happen including:

1) The compilation of ASP.NET pages takes longer (since some batch optimizations are disabled)
2) Code can execute slower (since some additional debug paths are enabled)
3) Much more memory is used within the application at runtime
4) Scripts and images downloaded from the WebResources.axd handler are not cached

This last point is particularly important, since it means that all client-javascript libraries and static images that are deployed via WebResources.axd will be continually downloaded by clients on each page view request and not cached locally within the browser.  This can slow down the user experience quite a bit for things like Atlas, controls like TreeView/Menu/Validators, and any other third-party control or custom code that deploys client resources.  Note that the reason why these resources are not cached when debug is set to true is so that developers don’t have to continually flush their browser cache and restart it every-time they make a change to a resource handler (our assumption is that when you have debug=true set you are in active development on your site).

When <compilation debug=”false”/> is set, the WebResource.axd handler will automatically set a long cache policy on resources retrieved via it – so that the resource is only downloaded once to the client and cached there forever (it will also be cached on any intermediate proxy servers).  If you have Atlas installed for your application, it will also automatically compress the content from the WebResources.axd handler for you when <compilation debug=”false”/> is set – reducing the size of any client-script javascript library or static resource for you (and not requiring you to write any custom code or configure anything within IIS to get it).

Monday, 24 February 2014

Expand / Collapse a node in ASP.Net TreeView through XML Attribute

.aspx page:

<asp:TreeView ID="TreeView1" runat="server" DataSourceID="xmlDs" OnPreRender="TreeView1_PreRender" EnableViewState="false"> </asp:TreeView>

 <asp:XmlDataSource ID="xmlDs" runat="server" XPath="Modules/Module"></asp:XmlDataSource>
.aspx.cs page:

 #region Expand/Collapse Nodes

    protected void TreeView1_PreRender(object sender, EventArgs e)
    {
        SelectCurrentPageTreeNode(tvNav);
    }

    private void SelectCurrentPageTreeNode(TreeView tvTreeView)
    {
        tvTreeView.CollapseAll();
        string currentPage = System.IO.Path.GetFileName(Request.Path);
        if (currentPage != null)
        {
            ExpandTreeViewNodes(tvTreeView, currentPage);
        }
    }

    private TreeNode ExpandTreeViewNodes(TreeView tvTreeView, string sPathAndQuery)
    {
        if (tvTreeView != null)
        {
            if (!string.IsNullOrEmpty(sPathAndQuery))
            {
                sPathAndQuery = sPathAndQuery.ToLower();
                {
                    TreeNode tnWorkTreeNode = null;

                    for (int iLoop = 0; iLoop < tvTreeView.Nodes.Count; iLoop++)
                    {
                        tvTreeView.Nodes[iLoop].Expand();

                        tvTreeView.Nodes[iLoop].Selected = true;
                        if (tvTreeView.Nodes[iLoop].NavigateUrl.ToLower() == sPathAndQuery)
                        {
                            return (tvTreeView.Nodes[iLoop]);
                        }
                        else
                        {
                            tnWorkTreeNode = ExpandTreeViewNodesR(tvTreeView.Nodes[iLoop], sPathAndQuery);
                        }

                        if (tnWorkTreeNode != null)
                        {
                            return (tnWorkTreeNode);
                        }

                        tvTreeView.Nodes[iLoop].Collapse();
                    }
                }
            }
        }

        return (null);
    }

    private static TreeNode ExpandTreeViewNodesR(TreeNode tvTreeNode, string sPathAndQuery)
    {
        TreeNode tnReturnTreeNode = null;

        if (tvTreeNode != null)
        {
            tvTreeNode.Expand();
            if (tvTreeNode.NavigateUrl.ToLower() == sPathAndQuery)
            {
                return (tvTreeNode);
            }
            else
            {
                tnReturnTreeNode = null;

                for (int iLoop = 0; iLoop < tvTreeNode.ChildNodes.Count; iLoop++)
                {
                    tvTreeNode.ChildNodes[iLoop].Selected = true;
                    tnReturnTreeNode = ExpandTreeViewNodesR(tvTreeNode.ChildNodes[iLoop], sPathAndQuery);

                    if (tnReturnTreeNode != null)
                    {
                        return (tnReturnTreeNode);
                    }
                }
                tvTreeNode.Collapse();
            }
        }
       return (null);
    }

    #endregion

Extracting Nupkg files using command line

Rename it to zip first then extract files as below 1.     Rename-Item -Path A_Package.nupkg -NewName A_Package.zip 2.     Make sure to repla...