Step by step migration of ASP.NET Core 2.2 to 3.1

In order to upgrade/migrate asp.net core version to 3.1 following steps to be perform.
Download and install Visual Studio 2019 version 16.4 or higher.Download and install .NET Core 3.1  https://dotnet.microsoft.com/download/dotnet-core/3.1Upgrade the projects of solution to .NET Core 3.1 , because ASP.NET Core 3.1 requires it.Update existing Nuget packages to a version compatible with ASP.NET Core 3.1 in each projectUse IHost interface from a IHostBuilder instead of building and running a IWebHost from a IWebHostBuilder in Program.cs public static IHostBuilder CreateWebHostBuilder(string[] args) => Host.CreateDefaultBuilder(args) .ConfigureWebHostDefaults(webBuilder => { webBuilder.UseKestrel() .UseSerilog() .UseStartup<Startup>(); }) Change AddMvc method has been replaced by AddControllers in Startup.cs of each projects.In Startup.cs,UseMvc method to be replaced by…

Restore the lost focus of Auto post back controls in asp.net update Panel control

Problem:
We put  autopostback controls like textbox, DropDownList controls inside in update panel to reducing the flickering of the Page.but when user uses tab for entering the details  the focus of the control losts. Web site users who prefer to use keyboard need to use mouse to activate appropriate input box or press TAB multiple times.

Solution:

Step 1:

Save following in js file give any name to it (like MyUpdatePanelFocus.js)

var lastFocusedControlId = "";

function focusHandler(e) {
    document.activeElement = e.originalTarget;
}

function appInit() {
    if (typeof (window.addEventListener) !== "undefined") {
        window.addEventListener("focus", focusHandler, true);
    }
    Sys.WebForms.PageRequestManager.getInstance().add_pageLoading(pageLoadingHandler);
    Sys.WebForms.PageRequestManager.getInstance().add_pageLoaded(pageLoadedHandler);
}

function pageLoadingHandler(sender, args) {
    lastFocusedControlId = typeof (document.activeElement) === "undefined"
        ? "" : document.activeElement.id;
}

function focusControl(targetControl) {
    if (Sys.Browser.agent === Sys.Browser.InternetExplorer) {
        var focusTarget = targetControl;
        if (focusTarget && (typeof (focusTarget.contentEditable) !== "undefined")) {
            oldContentEditableSetting = focusTarget.contentEditable;
            focusTarget.contentEditable = false;
        }
        else {
            focusTarget = null;
        }
        targetControl.focus();
        if (focusTarget) {
            focusTarget.contentEditable = oldContentEditableSetting;
        }
    }
    else {
        targetControl.focus();
    }
}

function pageLoadedHandler(sender, args) {
    if (typeof (lastFocusedControlId) !== "undefined" && lastFocusedControlId != "") {
        var newFocused = $get(lastFocusedControlId);
        if (newFocused) {
            focusControl(newFocused);
        }
    }
}

Sys.Application.add_init(appInit);

Step 2: Do the following setting in aspx page

    <asp:ScriptManager ID="c_scriptManager" runat="server">
        <Scripts>
            <asp:ScriptReference Path="~/MyUpdatePanelFocus.js" />
        </Scripts>
    </asp:ScriptManager>

That's it you have done it!!!!

Comments

  1. Thank you soooo much this is the only script i have found that has worked the way i wanted it to and was easy to implement.

    ReplyDelete
  2. GOOd work friend......keep it up.i am seraching thgis type code

    ReplyDelete
  3. Nice work, worked perfectly.

    ReplyDelete
  4. Hi,
    But it's not working in ModlelPopupExtender.
    u people having any solution.


    ReplyDelete
  5. oh nice yaar it is working ......thanks dear

    ReplyDelete
  6. Great Work.. After a long search got a perfect solution.

    ReplyDelete
  7. Really good concept (the most important pat). Great would be to also keep the cursor position for cases when user is in middle of editing.

    ReplyDelete
  8. realy great work!

    ReplyDelete
  9. This comment has been removed by the author.

    ReplyDelete

Post a Comment

Popular posts from this blog

Add Comma automatically while entering amounts in textbox using Javascript

Devexpress Datebox date formatting in angular 6 with example