简体   繁体   English

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

[英]AjaxToolkit ModalPopupExtender: How do I set focus to a control in the popup Panel?

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. 当用户按下Button时,我想显示一个模态对话框,从文本框中捕获几个值并将这些值提交给服务器。

When the modal box is shown, I'd like the cursor to be placed in the txtFirst textbox. 当显示模态框时,我希望将光标放在txtFirst文本框中。

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. 我之前遇到过registercript命令的问题,所以如果需要的话,我希望语法(如果你提供的话)是正确的。

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>
                        &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>

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 如果我设置targetcontrolid =“DropDownList1”,则会在删除时显示对话框,而不是在进行选择时显示

An example can be found here . 这里可以找到一个例子。 In essence you are using javascript. 从本质上讲,您使用的是javascript。

I know this was already answered, but here's an easier code: 我知道这已经回答了,但是这里的代码更简单:

C#: C#:

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

VB: VB:

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何以编程方式设置由ModalPopupExtender控制的面板中放置的Web控件的属性 - How to programmatically set properties of a Web control placed in a Panel controlled by a ModalPopupExtender 将重点放在弹出面板上 - Set the focus on Popup Panel 如何防止在回发时关闭模态弹出窗口(ModalPopupExtender)? - How do I prevent the closing of modal popup window(ModalPopupExtender) on postback? 如何在模式弹出窗口中将焦点设置到DropDownList控件? - How to Set Focus to a DropDownList control in a Modal Popup? 如何显示另一个ModalPopupExtender的ModalPopupExtender并设置必须首先显示的那个? - How do I display a ModalPopupExtender from another ModalPopupExtender and set which one has to be shown first? 如何使用GridView中的控件在ModalPopupExtender中设置TargetContrlID - How to set TargetContrlID in ModalPopupExtender with a control in a GridView AjaxToolkit ModalPopupExtender不在顶部 - AjaxToolkit ModalPopupExtender not on top 我可以在 Visual Studio 2005 中使用 ajaxToolkit:ModalPopupExtender - can i use ajaxToolkit:ModalPopupExtender in visual studio 2005 AjaxToolkit:ComboBox + AjaxToolkit:ModalPopupExtender — ComboBox下拉列表中断了……如何解决? - AjaxToolkit:ComboBox + AjaxToolkit:ModalPopupExtender — The ComboBox dropdown list cuts off… how to fix? 如何从服务器控件动态创建ModalPopupExtender控件? - How can i create a ModalPopupExtender control dynamically from a server control?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM