Asp.net AjaxModalPopupXtender:从下拉列表中选择项目时,如何显示对话框?
以下示例在用户单击按钮时显示一个模式对话框 当从下拉列表中进行选择时,我必须进行哪些更改才能使其显示对话框 请注意,如果我将TargetControlID属性从“Button1”设置为“DropDownList 1”,则在下拉列表被删除时,而不是在实际进行选择时,将显示该对话框Asp.net AjaxModalPopupXtender:从下拉列表中选择项目时,如何显示对话框?,asp.net,modalpopupextender,Asp.net,Modalpopupextender,以下示例在用户单击按钮时显示一个模式对话框 当从下拉列表中进行选择时,我必须进行哪些更改才能使其显示对话框 请注意,如果我将TargetControlID属性从“Button1”设置为“DropDownList 1”,则在下拉列表被删除时,而不是在实际进行选择时,将显示该对话框 <%@ Page Language="VB" AutoEventWireup="false" CodeFile="MyModalSimple.aspx.vb" Inherits="MyModalSimple" %&
<%@ 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>
<style type="text/css">
.modalBackground
{
background-color: Gray;
filter: alpha(opacity=70);
opacity: 0.7;
}
</style>
<link href="Default.css" rel="stylesheet" type="text/css" />
<script type="text/javascript">
function onOk() {
//form1.submit();
}
</script>
<script type="text/javascript">
var clientid;
function fnSetFocus(txtClientId) {
clientid = txtClientId;
setTimeout("fnFocus()", 500);
}
function fnFocus() {
eval("document.getElementById('" + clientid + "').focus()");
}
function fnClickOK(sender, e) {
__doPostBack(sender, e);
}
</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" />
<asp:DropDownList ID="DropDownList1" runat="server">
<asp:ListItem>1</asp:ListItem>
<asp:ListItem>2</asp:ListItem>
</asp:DropDownList>
<cc1:ModalPopupExtender ID="Button1_ModalPopupExtender" runat="server" TargetControlID="Button1"
PopupDragHandleControlID="programmaticPopupDragHandle" PopupControlID="pnlModal"
OkControlID="btnOK" CancelControlID="btnCancel" DropShadow="true" OnOkScript="onOk();"
BackgroundCssClass="modalBackground">
</cc1:ModalPopupExtender>
<asp:Panel ID="pnlModal" runat="server" Style="display: None" BackColor="#CCCCCC">
<asp:Panel runat="Server" ID="programmaticPopupDragHandle" Style="cursor: move; background-color: #DDDDDD;
border: solid 1px Gray; color: Black; text-align: center;">
Caption
</asp:Panel>
<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>
<asp:Label ID="lblMessage" runat="server"></asp:Label>
</div>
</form>
</body>
</html>
Partial Class MyModalSimple
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not Page.IsPostBack Then
Button1.Attributes.Add("onclick", "fnSetFocus('" + txtFirst.ClientID + "');")
btnOK.OnClientClick = String.Format("fnClickOK('{0}','{1}')", btnOK.UniqueID, "")
End If
End Sub
Protected Sub btnOK_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnOK.Click
lblMessage.Text = "Hi, " & txtFirst.Text & " " & txtLast.Text
End Sub
End Class
莫达尔巴基德先生
{
背景颜色:灰色;
过滤器:α(不透明度=70);
不透明度:0.7;
}
函数onOk(){
//表格1.提交();
}
变种clientid;
函数fnSetFocus(txtClientId){
clientid=txtClientId;
setTimeout(“fnFocus()”,500);
}
函数fnFocus(){
eval(“document.getElementById(“+clientid+”).focus()”;
}
功能FN单击确定(发送方,e){
__doPostBack(发送方,e);
}
1.
2.
说明文字
部分类MyModalSimple
继承System.Web.UI.Page
受保护的子页加载(ByVal sender作为对象,ByVal e作为System.EventArgs)处理Me.Load
如果不是Page.IsPostBack,则
Button1.Attributes.Add(“onclick”、“fnSetFocus(““+txtFirst.ClientID+”);”)
btnOK.OnClientClick=String.Format(“fnClickOK('{0}','{1}'),btnOK.UniqueID,”)
如果结束
端接头
受保护的子btnOK_Click(ByVal sender作为对象,ByVal e作为System.EventArgs)处理btnOK。单击
lblMessage.Text=“嗨,&txtFirst.Text&”“&txtLast.Text
端接头
末级
我已经这样做了,而且对我来说效果很好(在下拉列表的更改
事件处理程序中):
在本例中,我已将TargetControlID
设置为用户不可见的“虚拟”元素
if (this.value == "yourDropDownListValue") {
// get a reference to the popup extender element
var popupElement = $find("thePopupElementName");
if (popupElement != null) {
// show the popup extender
popupElement.show();
}
}