Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/37.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 回发后维护选项卡索引_C#_Asp.net - Fatal编程技术网

C# 回发后维护选项卡索引

C# 回发后维护选项卡索引,c#,asp.net,C#,Asp.net,我有一个带有4个文本框的订单页面,它们位于ajax updatepanel中。所有4个文本都已更改事件。此页中的所有控件均未设置TabIndex属性。当我在textbox1中输入文本并按下tab键时,会导致回发,但下一个焦点不是我想要的textbox2。而焦点则放在页面上。与所有文本框类似 此订单页使用母版页 母版页: <form id = "form1" runat="server"> <asp:ScriptManager ID="ScriptManager1 " runat

我有一个带有4个文本框的订单页面,它们位于ajax updatepanel中。所有4个文本都已更改事件。此页中的所有控件均未设置TabIndex属性。当我在textbox1中输入文本并按下tab键时,会导致回发,但下一个焦点不是我想要的textbox2。而焦点则放在页面上。与所有文本框类似

此订单页使用母版页

母版页:

<form id = "form1" runat="server">
<asp:ScriptManager ID="ScriptManager1 " runat="server" />
试试这个

protected void textbox1_TextChanged(object sender, EventArgs e)
{
   //someFunction();
   TextBox tb = (TextBox)FormOrder.FindControl("textbox2");
   tb.focus();
}
试试这个

protected void textbox1_TextChanged(object sender, EventArgs e)
{
   //someFunction();
   TextBox tb = (TextBox)FormOrder.FindControl("textbox2");
   tb.focus();
}

在名为i.e focus.js的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);
使用Scriptmanager引用它,如下所示:

<ajax:ScriptManager ID="ScriptManager1" runat="server">
        <Scripts>
            <ajax:ScriptReference Path="~/Js/FixFocus.js" />
        </Scripts>
    </ajax:ScriptManager>

在名为i.e focus.js的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);
使用Scriptmanager引用它,如下所示:

<ajax:ScriptManager ID="ScriptManager1" runat="server">
        <Scripts>
            <ajax:ScriptReference Path="~/Js/FixFocus.js" />
        </Scripts>
    </ajax:ScriptManager>

在选项卡上使用服务器端控件不是一个好做法。为什么不使用jQuery/Bootstrap呢?
使用当前的方法,您会使用许多无用的帖子/回发,这些帖子/回发会用无用的工作使服务器过载。

使用服务器端控件作为选项卡不是一个好做法。为什么不使用jQuery/Bootstrap呢?
按照您当前的方法,您会使用许多无用的帖子/回发,这些帖子/回发会使服务器超载,产生无用的工作。

我无法在订单页面中使用其他表单和脚本管理器,因为它们已经在主控中。所讨论的C#代码是我想使用的一种方法OK尝试参考下面的链接@Ruby It will work for your,无需在页面上添加另一个脚本管理器。@nrsharma。。非常感谢你。成功了。我所要做的就是将所有页面内容放在一个div中。我无法在订单页面中使用其他表单和脚本管理器,因为它们已经在master中了。所讨论的C#代码是我想使用的一种方法OK尝试参考下面的链接@Ruby It will work for your,无需在页面上添加另一个脚本管理器。@nrsharma。。非常感谢你。成功了。我所要做的就是把所有的页面内容放在一个div中。谢谢。我正在从C#和更简单的东西,因为我不知道JS。没问题,只要使用这个脚本,命名为focus.JS并引用它,如ScriptManager所示。会有用的,谢谢。我正在从C#和更简单的东西,因为我不知道JS。没问题,只要使用这个脚本,命名为focus.JS并引用它,如ScriptManager所示。它会起作用的。