ModalPopupExtender:文本框火灾的TextChanged方法后,弹出窗口关闭. [英] ModalPopupExtender: Popup Closes After TextChanged Method of Textbox FIres.
问题描述
使用JavaScript,我创建了一个包含文本框的弹出窗口".我通过一个按钮激活它.在文本框中输入数据后,将执行后面的相对代码,但清除了弹出窗口".就像按下了确定"按钮一样.
如何保持弹出窗口"的可见性,直到按下确定"或取消"按钮.
<%@页面语言="C#" AutoEventWireup ="true" CodeFile ="Test.aspx.cs" Inherits ="Test"%>
<!DOCTYPE html PUBLIC-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@注册程序集="AjaxControlToolkit"命名空间="AjaxControlToolkit" TagPrefix ="cc1"%>
< html xmlns ="http://www.w3.org/1999/xhtml">
< head runat ="server">
< title></title>
< link href ="Styles/StyleSheet.css" rel ="stylesheet" type ="text/css"/>
< script type ="text/javascript">
函数onOk(){
document.getElementById(''btnUpdateRates'').click();
}
</script>
</head>
< body>
< form id ="form1" runat ="server">
< cc1:ToolkitScriptManager ID ="ToolkitScriptManager1" runat =服务器" EnablePageMethods ="true">
< asp:Button ID ="btnCustCharges" runat ="server" Text =客户费用"/>
< asp:面板ID ="pnlCustCharge"宽度="275px" runat =服务器"
Style ="display:none">
上尉. | < asp:TextBox ID ="txtCaptRate" runat ="server" Height ="19px" Width ="40px" OnTextChanged ="txtCaptRate_TextChanged" AutoPostBack ="true"> | < asp:TextBox ID ="txtCaptAdminDol" ReadOnly ="true" runat ="server" Height ="19px" Width ="40px" BackColor ="Silver"> | < asp:TextBox ID ="txtCaptAdminPct" ReadOnly ="true" runat ="server" Height ="19px" Width ="40px" BackColor ="Silver"> | < asp:TextBox ID ="txtCaptCharge" ReadOnly ="true" runat ="server" Height ="19px" Width ="40px" BackColor ="Silver"> |
< cc1:ModalPopupExtender ID ="ModalPopupExtender1" runat =服务器" TargetControlID ="btnCustCharges"
PopupControlID ="pnlCustCharge" BackgroundCssClass ="modalBackground" DropShadow ="true"
EnableViewState ="true" OkControlID ="OkButton"önOkScript="onOk()" CancelControlID ="CancelButton"/>
</form>
</body>
</html>
方法后面的相对代码:
使用系统;
使用System.Collections.Generic;
使用System.Linq;
使用System.Web;
使用System.Web.UI;
使用System.Web.UI.WebControls;
公共局部类测试:System.Web.UI.Page
{
受保护的void Page_Load(对象发送者,EventArgs e)
{
如果(!IsPostBack)
{
txtCaptRate.Text ="36.90";
txtCaptAdminDol.Text ="5.00";
txtCaptAdminPct.Text ="13.55";
txtCaptCharge.Text ="41.90";
txtLtRate.Text ="33.68";
txtLtAdminDol.Text ="5.00";
txtLtAdminPct.Text ="14.84";
txtLtCharge.Text ="38.68";
txtSgtRate.Text ="32.10";
txtSgtAdminDol.Text ="4.82";
txtSgtAdminPct.Text ="15.00";
txtSgtCharge.Text ="36.92";
txtPORate.Text ="29.33";
txtPOAdminDol.Text ="4.40";
txtPOAdminPct.Text ="15.00";
txtPOCharge.Text ="29.33";
}
}
受保护的void UpdateCustCost(字符串等级)
{
十进制thepct = 0,thecost = 0,thedol = 0,therate = 0,thefee = 0,maxfee = 0;
开关(等级)
{
案例"Capt":
therate = Convert.ToDecimal(txtCaptRate.Text);
maxfee =费率*(十进制).15;
如果(maxfee> 5)
{
thefee = 5;
}
其他
{
thefee = maxfee;
}
thepct =费用/费率* 100;
thedol =费率+费用;
txtCaptAdminDol.Text = String.Format("{0:00.00}",thefee);
txtCaptAdminPct.Text = String.Format("{0:00.00}",thepct);
thecost =费率+费用;
txtCaptCharge.Text = String.Format("{0:00.00}",thecost);
休息;
}
}
受保护的void txtCaptRate_TextChanged(对象发送者,EventArgs e)
{
//重新计算总费用
UpdateCustCost("Capt");
}
}
添加
ModalPopupExtender1.Show(); //作为函数的最后一行
在txtCaptRate_TextChanged方法中
受保护的 无效 txtCaptRate_TextChanged(对象发件人,EventArgs e) { // 重新计算总费用 UpdateCustCost(&"Capt&"); ModalPopupExtender1.Show(); } 接受作为答案,如果解决了您的问题.
>
Using javascript, I have created a "popup" that contains a textbox. I activate it via a button. Once I enter data into the text box, the relative code behind executes, but the "popup" is cleared. It''s as if the "Ok" button is pressed.
How do maintain the visibility of the "popup" until the "Ok" or "Cancel" button is pressed.
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Test.aspx.cs" Inherits="Test" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<link href="Styles/StyleSheet.css" rel="stylesheet" type="text/css" />
<script type="text/javascript">
function onOk() {
document.getElementById(''btnUpdateRates'').click();
}
</script>
</head>
<body>
<form id="form1" runat="server">
<cc1:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server" EnablePageMethods="true">
<asp:Button ID="btnCustCharges" runat="server" Text="Customer Cost(s)" />
<asp:Panel ID="pnlCustCharge" Width="275px" runat="server"
Style="display: none">
Capt. | <asp:TextBox ID="txtCaptRate" runat="server" Height="19px" Width="40px" OnTextChanged="txtCaptRate_TextChanged" AutoPostBack="true"> | <asp:TextBox ID="txtCaptAdminDol" ReadOnly="true" runat="server" Height="19px" Width="40px" BackColor="Silver"> | <asp:TextBox ID="txtCaptAdminPct" ReadOnly="true" runat="server" Height="19px" Width="40px" BackColor="Silver"> | <asp:TextBox ID="txtCaptCharge" ReadOnly="true" runat="server" Height="19px" Width="40px" BackColor="Silver" > |
<cc1:ModalPopupExtender ID="ModalPopupExtender1" runat="server" TargetControlID="btnCustCharges"
PopupControlID="pnlCustCharge" BackgroundCssClass="modalBackground" DropShadow="true"
EnableViewState="true" OkControlID="OkButton" önOkScript="onOk()" CancelControlID="CancelButton" />
</form>
</body>
</html>
Relative Code behind methods:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class Test : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
txtCaptRate.Text="36.90";
txtCaptAdminDol.Text = "5.00";
txtCaptAdminPct.Text = "13.55";
txtCaptCharge.Text = "41.90";
txtLtRate.Text = "33.68";
txtLtAdminDol.Text = "5.00";
txtLtAdminPct.Text = "14.84";
txtLtCharge.Text = "38.68";
txtSgtRate.Text = "32.10";
txtSgtAdminDol.Text = "4.82";
txtSgtAdminPct.Text = "15.00";
txtSgtCharge.Text = "36.92";
txtPORate.Text = "29.33";
txtPOAdminDol.Text = "4.40";
txtPOAdminPct.Text = "15.00";
txtPOCharge.Text = "29.33";
}
}
protected void UpdateCustCost(string rank)
{
decimal thepct = 0, thecost = 0, thedol = 0, therate=0, thefee=0, maxfee=0;
switch (rank)
{
case "Capt":
therate = Convert.ToDecimal(txtCaptRate.Text);
maxfee = therate * (decimal).15;
if (maxfee > 5)
{
thefee = 5;
}
else
{
thefee = maxfee;
}
thepct = thefee / therate * 100;
thedol = therate + thefee;
txtCaptAdminDol.Text = String.Format("{0:00.00}", thefee);
txtCaptAdminPct.Text = String.Format("{0:00.00}", thepct);
thecost = therate + thefee;
txtCaptCharge.Text = String.Format("{0:00.00}", thecost);
break;
}
}
protected void txtCaptRate_TextChanged(object sender, EventArgs e)
{
//Recalculate Total Cost
UpdateCustCost("Capt");
}
}
Add
ModalPopupExtender1.Show(); // as last line of function
in txtCaptRate_TextChanged method
protected void txtCaptRate_TextChanged(object sender, EventArgs e) { //Recalculate Total Cost UpdateCustCost("Capt"); ModalPopupExtender1.Show(); } Accept as answer if solve you problem.
这篇关于ModalPopupExtender:文本框火灾的TextChanged方法后,弹出窗口关闭.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!