Friday 14 October 2016

Preserve scroll position of DIV in UpdatePanel through Postback in asp.net







<script type="text/javascript">

    window.onload = function () {
        var div = document.getElementById("divid");
        var div_position = document.getElementById("div_position");
        var position = parseInt('<%=Request.Form["div_position"] %>');
        if (isNaN(position)) {
            position = 0;
        }
        div.scrollTop = position;
        div.onscroll = function () {
            div_position.value = div.scrollTop;
        };
    };

</script>

  <div id="divid" style="width:97%; overflow:auto; min-height: 430px; max-height: 430px;">
// Your Code
</div>
<input type="hidden" id="Hidden1" name="div_position" />

Maintain Page Scroll Position On Partial Postback ASP.NET


// add in page directory

<%@ Page Title="" Language="C#" MasterPageFile="~/Master Pages/MainMaster.master"

    MaintainScrollPositionOnPostback="true" %>

Maintain Panel Scroll Position On Partial Postback ASP.NET




<script type="text/javascript">
            // It is important to place this JavaScript code after ScriptManager1
            var xPos, yPos; // Set X and Y positions
            var prm = Sys.WebForms.PageRequestManager.getInstance();

            function BeginRequestHandler(sender, args) {
                if ($get('<%=pnl_memgrid.ClientID%>') != null) {
                    // Get X and Y positions of scrollbar before the partial postback
                    xPos = $get('<%=pnl_memgrid.ClientID%>').scrollLeft;
                    yPos = $get('<%=pnl_memgrid.ClientID%>').scrollTop;
                }
            }

            function EndRequestHandler(sender, args) {
                if ($get('<%=pnl_memgrid.ClientID%>') != null) {
                    // Set X and Y positions back to the scrollbar
                    // after partial postback or full post back
                    $get('<%=pnl_memgrid.ClientID%>').scrollLeft = xPos;
                    $get('<%=pnl_memgrid.ClientID%>').scrollTop = yPos;
                }
            }

            prm.add_beginRequest(BeginRequestHandler);
            prm.add_endRequest(EndRequestHandler);

 </script>

Export multiple DataTable to multiple Excel sheets using OpenXml in ASP.Net




protected void Btn_MSExport_Click(object sender, EventArgs e)
    {
        DataSet ds = getDataSetExportToExcel();
                ds.Tables[0].TableName = "Customers";
                ds.Tables[1].TableName = "Employees";
        using (XLWorkbook wb = new XLWorkbook())
        {
            wb.Worksheets.Add(ds);
            wb.Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Center;
            wb.Style.Font.Bold = true;

            Response.Clear();
            Response.Buffer = true;
            Response.Charset = "";
            Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
            Response.AddHeader("content-disposition", "attachment;filename= EmployeeAndOrderReport.xlsx");

            using (MemoryStream MyMemoryStream = new MemoryStream())
            {
                wb.SaveAs(MyMemoryStream);
                MyMemoryStream.WriteTo(Response.OutputStream);

                Response.Flush();
                Response.End();
            }
        }

    }

Excel Sort values in ascending order using function TEXTJOIN

 Excel ::  Text ::  1,3,5,2,9,5,11 Result :: 1,2,3,5,5,9,11 Formula ::     TEXTJOIN ( ",",1,SORT(MID(SUBSTITUTE( A1 ,","...