Click here to Skip to main content
15,904,416 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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");

}
}
Posted
Updated 6-Jul-13 15:46pm
v2

Add
ModalPopupExtender1.Show(); // as last line of function
in txtCaptRate_TextChanged method
 
Share this answer
 
v2
C#
protected void txtCaptRate_TextChanged(object sender, EventArgs e)
{
//Recalculate Total Cost
UpdateCustCost(&quot;Capt&quot;);
ModalPopupExtender1.Show();

}



Accept as answer if solve you problem.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900