本文介绍了如何在C#中的Ajaxtoolkitcontrol弹出窗口中单击带空格键的按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个由面板创建的弹出窗口,在C#中使用服务器端的Ajaxtoolkitcontrol。有一个名为OK的按钮。我想按键盘上的空格键来点击按钮。这该怎么做?代码如下:



aspx:

I have a popup window created by panel, using Ajaxtoolkitcontrol from server side in C#. There is a button named "OK". I want to press space key in keyboard to click the button. How to do this? The code is below:

aspx:

<asp:Panel ID="PanelDlg" runat="server" BorderStyle="Solid" BorderWidth="2px"
Width="300px" Height="186px" style="display:none" Font-Bold="True">
    <asp:Panel ID="PanelBar" runat="server" BackColor="#0000CC"
        BorderColor="Black" BorderStyle="Solid" BorderWidth="1px" Height="25px" HorizontalAlign="Right">
        <asp:ImageButton ID="ImageButtonExit" runat="server" ImageUrl="~/ico/close1.png"
        OnClick="ImageButtonExit_Click"/>
    </asp:Panel>
    <asp:Panel ID="PanelContent" runat="server" Height="158px" HorizontalAlign="Center" BackColor="#D4D4D4">
        <br></br>
        <asp:Label ID="LabelText" runat="server" Text="Label"></asp:Label>
        <br></br>
        <br></br>
        <asp:Button ID="btnOK" runat="server" Height="27px" style="margin-left: 0px"
            Text="OK" Width="64px" OnClick="btnOK_Click" Font-Bold="True" />
        <br>
        </br>
        <br>
        </br>
        <br>
    </br>
    </asp:Panel>
</asp:Panel>



cs:


cs:

protected void popupDlg(string dlgText)
{
    ModalPopupExtender modalPopup = new ModalPopupExtender();

    modalPopup.ID = "popupDlg";
    modalPopup.TargetControlID = "btnDlg";
    modalPopup.PopupControlID = "PanelDlg";
    modalPopup.PopupDragHandleControlID = "PanelBar";
    modalPopup.DropShadow = true;
    confirmModal.Controls.Add(modalPopup);
    LabelText.Text = dlgText;

    modalPopup.Show();
}

推荐答案

<asp:Panel ID="PanelDlg" runat="server" BorderStyle="Solid" BorderWidth="2px"

Width="300px" Height="186px" style="display:none" Font-Bold="True">
    <asp:Panel ID="PanelBar" runat="server" BackColor="#0000CC"

        BorderColor="Black" BorderStyle="Solid" BorderWidth="1px" Height="25px" HorizontalAlign="Right">
        <asp:ImageButton ID="ImageButtonExit" runat="server" ImageUrl="~/ico/close1.png"

        OnClick="ImageButtonExit_Click"  />
    </asp:Panel>
    <asp:Panel ID="PanelContent" runat="server" Height="158px" HorizontalAlign="Center" BackColor="#D4D4D4">
        <br></br>
        <asp:Label ID="LabelText" runat="server" Text="Label"></asp:Label>
        <br></br>
        <br></br>
        <asp:Button ID="btnOK" runat="server" Height="27px" style="margin-left: 0px"

            Text="OK" Width="64px" OnClick="btnOK_Click" KeyUp="btnOK_KeyUp" Font-Bold="True" />
        <br>
        </br>
        <br>
        </br>
        <br>
    </br>
    </asp:Panel>
</asp:Panel>










private void btnOK_Click(object sender, KeyEventArgs e)
        {
            try
            {
                if (e.Key == Key.Space) // any key what you want to press that enter here.
                {
                    popupDlg("Enter your Message what you want to show")
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }







protected void popupDlg(string dlgText)
{
    ModalPopupExtender modalPopup = new ModalPopupExtender();
 
    modalPopup.ID = "popupDlg";
    modalPopup.TargetControlID = "btnDlg";
    modalPopup.PopupControlID = "PanelDlg";
    modalPopup.PopupDragHandleControlID = "PanelBar";
    modalPopup.DropShadow = true;
    confirmModal.Controls.Add(modalPopup);
    LabelText.Text = dlgText;
 
    modalPopup.Show();
}


这篇关于如何在C#中的Ajaxtoolkitcontrol弹出窗口中单击带空格键的按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-27 13:46