AjaxToolkit ModalPopupExtender:如何将焦点设置到弹出面板中的控件?

发布于 2024-08-17 13:14:33 字数 2928 浏览 2 评论 0原文

当用户按下按钮时,我想显示一个模式对话框以从文本框中捕获几个值并将这些值提交到服务器。

当显示模式框时,我希望将光标放置在 txtFirst 文本框中。

我该怎么做?我以前在使用 registerscript 命令时遇到过麻烦,所以如果需要的话,我希望语法(如果您提供的话)是正确的。

谢谢

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="MyModalSimple.aspx.vb" Inherits="MyModalSimple" %>
<%@ Register assembly="AjaxControlToolkit" namespace="AjaxControlToolkit" tagprefix="cc1" %>

<!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 type="text/javascript">

        function onOk() {            
            form1.submit();
        }
    </script>

</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:ScriptManager ID="ScriptManager1" runat="server">
        </asp:ScriptManager>
        <asp:Button ID="Button1" runat="server" Text="Button" />
        <cc1:modalpopupextender id="Button1_ModalPopupExtender" runat="server" targetcontrolid="Button1"
            popupcontrolid="pnlModal" okcontrolid="btnOK" cancelcontrolid="btnCancel"   DropShadow="true"  OnOkScript="onOk();">

        </cc1:modalpopupextender>

        <asp:Panel ID="pnlModal" runat="server" Style="display: None1" 
            BackColor="#CCCCCC">
            <br />
            <table>
                <tr>
                    <td>
                        <asp:Label ID="lblFirst" runat="server" Text="First"></asp:Label>
                    </td>
                    <td>
                        <asp:TextBox ID="txtFirst" runat="server"></asp:TextBox>
                    </td>
                </tr>
                <tr>
                    <td>
                        <asp:Label ID="lblLast" runat="server" Text="Last"></asp:Label>
                    </td>
                    <td>
                        <asp:TextBox ID="txtLast" runat="server"></asp:TextBox>
                    </td>
                </tr>
                <tr>
                    <td>
                        &nbsp;
                    </td>
                    <td align="right">
                        <asp:Button ID="btnOK" runat="server" Text="OK" />
                        <asp:Button ID="btnCancel" runat="server" Text="Cancel" />
                    </td>
                </tr>
            </table>
            <br />
            <br />
        </asp:Panel>

    </div>
    </form>
</body>
</html>

另外,我如何更改上面的代码,以便通过选择下拉列表项来显示模式对话框?如果我设置 targetcontrolid="DropDownList1",则对话框会在放下时显示,而不是在进行选择时显示

When the user pushes the Button, I'd like to display a modal dialog box to capture a couple of values from text boxes and submit these values to the server.

When the modal box is shown, I'd like the cursor to be placed in the txtFirst textbox.

How do I do this? I've had trouble with registerscript commands before, so if one is needed, I hope the syntax, if you provide it, is correct.

Thanks

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="MyModalSimple.aspx.vb" Inherits="MyModalSimple" %>
<%@ Register assembly="AjaxControlToolkit" namespace="AjaxControlToolkit" tagprefix="cc1" %>

<!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 type="text/javascript">

        function onOk() {            
            form1.submit();
        }
    </script>

</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:ScriptManager ID="ScriptManager1" runat="server">
        </asp:ScriptManager>
        <asp:Button ID="Button1" runat="server" Text="Button" />
        <cc1:modalpopupextender id="Button1_ModalPopupExtender" runat="server" targetcontrolid="Button1"
            popupcontrolid="pnlModal" okcontrolid="btnOK" cancelcontrolid="btnCancel"   DropShadow="true"  OnOkScript="onOk();">

        </cc1:modalpopupextender>

        <asp:Panel ID="pnlModal" runat="server" Style="display: None1" 
            BackColor="#CCCCCC">
            <br />
            <table>
                <tr>
                    <td>
                        <asp:Label ID="lblFirst" runat="server" Text="First"></asp:Label>
                    </td>
                    <td>
                        <asp:TextBox ID="txtFirst" runat="server"></asp:TextBox>
                    </td>
                </tr>
                <tr>
                    <td>
                        <asp:Label ID="lblLast" runat="server" Text="Last"></asp:Label>
                    </td>
                    <td>
                        <asp:TextBox ID="txtLast" runat="server"></asp:TextBox>
                    </td>
                </tr>
                <tr>
                    <td>
                         
                    </td>
                    <td align="right">
                        <asp:Button ID="btnOK" runat="server" Text="OK" />
                        <asp:Button ID="btnCancel" runat="server" Text="Cancel" />
                    </td>
                </tr>
            </table>
            <br />
            <br />
        </asp:Panel>

    </div>
    </form>
</body>
</html>

Also, how could I change the above code so that the modal dialog was displayed as a result of a selection of a dropdownlist item? If I set the targetcontrolid="DropDownList1", the dialog box is display when it drops rather than when a selection is made

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

自演自醉 2024-08-24 13:14:33

可以在此处找到示例。本质上你正在使用 javascript。

An example can be found here. In essence you are using javascript.

蓝天白云 2024-08-24 13:14:33

我知道这个问题已经得到解答,但这里有一个更简单的代码:

C#:

ScriptManager.RegisterStartupScript(this, this.GetType(), "FocusScript", "setTimeout(function(){$get('" + btnOk.ClientID + "').focus();}, 100);", true);

VB:

ScriptManager.RegisterStartupScript(Me, Me.[GetType](), "FocusScript", "setTimeout(function(){$get('" + btnOk.ClientID + "').focus();}, 100);", True)

I know this was already answered, but here's an easier code:

C#:

ScriptManager.RegisterStartupScript(this, this.GetType(), "FocusScript", "setTimeout(function(){$get('" + btnOk.ClientID + "').focus();}, 100);", true);

VB:

ScriptManager.RegisterStartupScript(Me, Me.[GetType](), "FocusScript", "setTimeout(function(){$get('" + btnOk.ClientID + "').focus();}, 100);", True)
一梦等七年七年为一梦 2024-08-24 13:14:33

从控制面板中删除 Style="display: None1"

Remove Style="display: None1" from control panel

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文