KV D
asked on
How to show selected values from drop down and text box on the popup?
Please suggest how to show the values selected from the drop down lists (ddlTotalingLevelB, ddlTotalingLevelC etc) and text box (txtTotalingLevel1) on the popup?
I tried as shown in the code below. The popup is working, but it shows the string as typed in the code instead of showing values
I tried as shown in the code below. The popup is working, but it shows the string as typed in the code instead of showing values
<asp:modalpopupextender id="ModalPopupExtender1" runat="server"
targetcontrolid="ButtonTotalingLevel" popupcontrolid="Panel1"
popupdraghandlecontrolid="PopupHeader" drag="true"
backgroundcssclass="ModalPopupBG">
</asp:modalpopupextender>
<asp:Panel ID="Panel1" runat="server">
<div class="ConfirmationPopup">
<div class="PopupHeader" id="PopupHeader">Confirm to add new level</div>
<div class="PopupBody">
<p>ddlTotalingLevelA.SelectedItem.Text+" "+ddlTotalingLevelB.SelectedItem.Text+" "+txtTotalingLevel1.Text</p>
</div>
<div class="Controls">
<asp:Button ID="btnOkay" runat="server" Text="Add New Totaling Level" OnClick ="ButtonTotalingLevel_Click" />
<asp:Button ID="btnCancel" runat="server" Text="Cancel" OnClick ="DoNothing" />
</div>
</div>
</asp:Panel>
ASKER
I did not get any suggestion, even though I had posted my code above. Let me try again. Thanks for your help in advance.
My goal is to validate that required fields are not null or empty, show a popup that shows current values selected/entered and take confirmation from the user to add new data to the database.
I have changed my code as follows. It is now partly working as it is showing the confirmation box popup and ok and cancel buttons work as expected. It also checks the required fields. But it still does not show the values selected on the drop down list and the text from the textbox on the confirmation box. Please check my code and suggest correction.
newlevel.aspx:
JavaScriptValidations.js:
newlevel.aspx.cs:
My goal is to validate that required fields are not null or empty, show a popup that shows current values selected/entered and take confirmation from the user to add new data to the database.
I have changed my code as follows. It is now partly working as it is showing the confirmation box popup and ok and cancel buttons work as expected. It also checks the required fields. But it still does not show the values selected on the drop down list and the text from the textbox on the confirmation box. Please check my code and suggest correction.
newlevel.aspx:
<%@ Page Title="" Language="C#" MasterPageFile="~/Main.Master" AutoEventWireup="true" CodeBehind="newlevels.aspx.cs" Inherits="COA.newlevels" EnableEventValidation="false" UnobtrusiveValidationMode="None" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
<script src="jquery-1.7.2.js" type="text/javascript"></script>
<script src="JavaScriptValidations.js"></script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
<div>
<table>
<tr>
<td>Totaling Level A</td>
<td>
<asp:DropDownList ID="ddlTotalingLevelA" runat="server" Width="250" OnSelectedIndexChanged="ddlTotalingLevelA_SelectedIndexChanged" ></asp:DropDownList>
<asp:CascadingDropDown ID="cdlTotalingLevelA" TargetControlID="ddlTotalingLevelA" PromptText="Select Totaling Level A"
PromptValue="" ServicePath="ServiceCS.asmx" ServiceMethod="GetLevelAList" runat="server"
Category="TOTALING_LEVEL_A" LoadingText="Loading..." />
<asp:RequiredFieldValidator ID="ddlARequired" runat="server" ControlToValidate="ddlTotalingLevelA"
CssClass="failureNotification" ErrorMessage="ddlA required." ToolTip="ddlA is required."
ValidationGroup="NewLevelValidationGroup">*</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td>Totaling Level B</td>
<td>
<asp:DropDownList ID="ddlTotalingLevelB" runat="server" Width="250" OnSelectedIndexChanged="ddlTotalingLevelB_SelectedIndexChanged"></asp:DropDownList>
<asp:CascadingDropDown ID="cdlTotalingLevelB" TargetControlID="ddlTotalingLevelB" PromptText="Select Totaling Level B"
PromptValue="" ServicePath="ServiceCS.asmx" ServiceMethod="GetLevelBList" runat="server"
Category="TOTALING_LEVEL_B" ParentControlID="ddlTotalingLevelA" LoadingText="Loading..." />
</td>
<td> </td>
<td> </td>
<td>
<asp:TextBox ID="txtTotalingLevel1" runat="server" required></asp:TextBox></td>
<asp:RequiredFieldValidator ID="txtFieldValidator" runat="server" ControlToValidate="txtTotalingLevel1"
CssClass="failureNotification" ErrorMessage="txtA required." ToolTip="txtA is required."
ValidationGroup="NewLevelValidationGroup">*</asp:RequiredFieldValidator>
<td>
<asp:Button ID="ButtonTotalingLevel" runat="server" Text="Add New Totaling Level" OnClick="ButtonTotalingLevel_Click" ValidationGroup ="NewLevelValidationGroup" OnClientClick ="performCheck(); " /></td>
</tr>
</table>
</div>
</asp:Content>
JavaScriptValidations.js:
function performCheck() {
Page_ClientValidate("NewLevelValidationGroup");
var ddl1 = document.getElementById('#ddlTotalingLevelA');
var newlevel = document.getElementById('#txtTotalingLevel1');
if (Page_IsValid) {
return confirm("Are you sure you want to add " + newlevel + "under " + ddl1);
}
}
newlevel.aspx.cs:
public partial class newlevels : System.Web.UI.Page
{
String ddlTotalingLevelAValue;
String ddlTotalingLevelBValue;
//String ddlTotalingLevelCValue;
//String ddlTotalingLevelDValue;
// String ddlTotalingLevelEValue;
//String ddlTotalingLevelFValue;
SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["constr"].ToString());
protected void Page_Load(object sender, EventArgs e)
{
if (IsPostBack) { Response.Write("Postback"); }
}
protected void ButtonTotalingLevel_Click(object sender, EventArgs e)
{
if (!String.IsNullOrEmpty(ddlTotalingLevelAValue))
{
connection.Open();
SqlCommand cmd = connection.CreateCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText = "Insert into .....";
Response.Write(" <br /> " + cmd.CommandText);
cmd.ExecuteNonQuery();
connection.Close();
}
}
protected void ddlTotalingLevelA_SelectedIndexChanged(object sender, EventArgs e)
{
ddlTotalingLevelAValue = "'" + ddlTotalingLevelA.SelectedItem.Value.ToString() + "'";
}
protected void ddlTotalingLevelB_SelectedIndexChanged(object sender, EventArgs e)
{
ddlTotalingLevelAValue = "'" + ddlTotalingLevelA.SelectedItem.Value.ToString() + "'";
ddlTotalingLevelBValue = "'" + ddlTotalingLevelB.SelectedItem.Value.ToString() + "'";
}
<p>ddlTotalingLevelA.Selec tedItem.Te xt+" "+ddlTotalingLevelB.Select edItem.Tex t+" "+txtTotalingLevel1.Text</ p>
You should be using .Value instead.
You should be using .Value instead.
ASKER
Kyle, do you mean that code on the javascript performCheck() function?
I tried that on the javascript, but it throws error: 0x800a1391 - JavaScript runtime error: 'txtTotalingLevel1' is undefined
I tried that on the javascript, but it throws error: 0x800a1391 - JavaScript runtime error: 'txtTotalingLevel1' is undefined
if (Page_IsValid) {
return confirm("Are you sure you want to add " + txtTotalingLevel1.Text + "under " + ddlTotalingLevelA.SelectedItem.Text);
}
you have to wrap it in server side code:
var textBox = document.getElementById('<%= txtTotalingLevel1.ClientID %>');
var ddl = document.getElementById('<%= ddlTotalingLevelA.ClientID %>');
confirm ("Are you sure you want to add " + textBox.value + " under " + ddl.value );
ASKER
I had tried it earlier and again now, but that throws error: 0x800a138f - JavaScript runtime error: Unable to get property 'value' of undefined or null reference.
function performCheck() {
Page_ClientValidate("NewLevelValidationGroup");
var textBox = document.getElementById('<%= txtTotalingLevel1.ClientID %>');
var ddl = document.getElementById('<%= ddlTotalingLevelA.ClientID %>');
if (Page_IsValid) {
return confirm("Are you sure you want to add " + textBox.value + " under " + ddl.value);
}
}
for testing:
alert(textBox);
alert(ddl);
see which one you're having an issue with. need to grab a reference to the control and then reference the value in javascript.
alert(textBox);
alert(ddl);
see which one you're having an issue with. need to grab a reference to the control and then reference the value in javascript.
ASKER
both display null.
function performCheck() {
Page_ClientValidate("NewLevelValidationGroup");
var textBox = document.getElementById('<%= txtTotalingLevel1.ClientID %>');
var ddl = document.getElementById('<%= ddlTotalingLevelA.ClientID %>');
alert("textBox "+textBox);
alert("ddl "+ddl);
if (Page_IsValid) {
return confirm("Are you sure you want to add " );
//return confirm("Are you sure you want to add " + textBox.value + " under " + ddl.value);
}
}
View the page source, compare in this function the value returned replaced in
var textBox = document.getElementById('< %= txtTotalingLevel1.ClientID %>');
with the actual ID of the textbox.
var textBox = document.getElementById('<
with the actual ID of the textbox.
ASKER
I looked at the source on console (using F 12) and see that the two ids were ContentPlaceHolder1_txtTot alingLevel 1and ContentPlaceHolder1_ddlTot alingLevel A. I replaced those on the code, but still both alerts display null.
function performCheck() {
Page_ClientValidate("NewLevelValidationGroup");
var textBox = document.getElementById('<%= ContentPlaceHolder1_txtTotalingLevel1.ClientID %>');
var ddl = document.getElementById('<%= ContentPlaceHolder1_ddlTotalingLevelA.ClientID %>');
alert("textBox "+textBox);
alert("ddl "+ddl);
if (Page_IsValid) {
return confirm("Are you sure you want to add " );
//return confirm("Are you sure you want to add " + textBox.value + " under " + ddl.value);
}
}
Undo these last changes.
What is the id of the actual textbox when you view the source?
does the document.getElementById('. ..') match? if not, what is the value inside the quotes?
What is the id of the actual textbox when you view the source?
does the document.getElementById('.
ASKER
this is what I see in the source and I used the values from the id attribute of each control.
<select name="ctl00$ContentPlaceHolder1$ddlTotalingLevelA" id="ContentPlaceHolder1_ddlTotalingLevelA" required="" style="width:250px;">
<td>
<input name="ctl00$ContentPlaceHolder1$txtTotalingLevel1" type="text" id="ContentPlaceHolder1_txtTotalingLevel1" required="" /></td>
<span id="ContentPlaceHolder1_txtFieldValidator" title="txtA is required." class="failureNotification" style="visibility:hidden;">*</span>
<td>
confirm when you view the source :
var textBox = document.getElementById('< %= txtTotalingLevel1.ClientID %>');
should render as
var textBox = document.getElementById('C ontentPlac eHolder1_t xtTotaling Level1');
see if you can get access to the textbox in the console as well by:
document.getElementById('C ontentPlac eHolder1_t xtTotaling Level1');
var textBox = document.getElementById('<
should render as
var textBox = document.getElementById('C
see if you can get access to the textbox in the console as well by:
document.getElementById('C
ASKER
I was not able to find var textBox in the source. I am copying the whole source from the F12 debugger window.
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head><title>
CHART OF ACCOUNTS
</title><link href="style/Main.css" rel="stylesheet" />
<script src="jquery-1.7.2.js" type="text/javascript"></script>
<script src="JavaScriptValidations.js"></script>
<link href="/WebResource.axd?d=UT1Cj7SEzX8U-GEgOjD-qymnfcMJm4XMbcBSQ3_rs56nTaHpgOJJKEGkIpqkoQBZyywRvVbwSPCQIy7DJqruSuP2eKdZFCifp9Cjl2eJwJySekw1-YRPH9beWh6I5Ddq10BQL-PIqS_2EoTVXGxb5g2&t=636262998956572460" type="text/css" rel="stylesheet" /></head>
<body>
<form method="post" action="./newlevels.aspx" onsubmit="javascript:return WebForm_OnSubmit();" id="form1">
<div class="aspNetHidden">
<input type="hidden" name="__EVENTTARGET" id="__EVENTTARGET" value="" />
<input type="hidden" name="__EVENTARGUMENT" id="__EVENTARGUMENT" value="" />
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="3ytiFoeeALza1Hah7mL8/6GJV+yZyDrx+Dh29kVLja6z5e0FndiWoYub6ASWxLuJWGT36pYTpaeKt/3pdyCTUJTWkmep4S6PyLlXy5hk+2S32RbPB1n6V8kdAQfoYGPmpqdmRHMMDE/mtzp0ceDdQWePes3nlA1usoxLuDKVILq8Lg6a+4rlT/8AGcyNKM5qvXUn86Uy423qMqVwNmIWRh+hJhnVn7DCVB4HIWXxX5gS6sTIh24joH6FHUAjbxE/GlP8imsWaAicjck+DBJduDU/jNwt3tD5L1len/rcJ/s=" />
</div>
<script type="text/javascript">
//<![CDATA[
var theForm = document.forms['form1'];
if (!theForm) {
theForm = document.form1;
}
function __doPostBack(eventTarget, eventArgument) {
if (!theForm.onsubmit || (theForm.onsubmit() != false)) {
theForm.__EVENTTARGET.value = eventTarget;
theForm.__EVENTARGUMENT.value = eventArgument;
theForm.submit();
}
}
//]]>
</script>
<script src="/WebResource.axd?d=pynGkmcFUV13He1Qd6_TZHCVoeQDsLwW1_yqwEXf19znddiI1k66G9zvxV5r3yAx4SqHMo3vsytPTbSDXihzfg2&t=636160664560000000" type="text/javascript"></script>
<script src="/ScriptResource.axd?d=nv7asgRUU0tRmHNR2D6t1ETKqkyIrj3WnSeEcijTTsWKL0PBwbYt5oEQ889CDLFV0y1M9p9lAnwqvuz1d4NV3TD36yCFwtlP5wRmaW4sHF9ZTlnzoE_DsO123F_PLbd978PCn5f5of6A2U5soLVZqA2&t=ffffffffbc20153d" type="text/javascript"></script>
<script src="/ScriptResource.axd?d=D9drwtSJ4hBA6O8UhT6CQgM3A8KTxZUGWTmA-kbmJoYYvgbo-_TozR11Pi6GvwWhreGf_ZijimQ360y8a3jy1dKOS6TPzSA6Pk5EOI41I_SxyEzEpX4DBW1Irkez_yYaS39tuVPusTDfjzf3yjZcKl4aR-qqMAXQHrkn9eC35iE1&t=2a48f442" type="text/javascript"></script>
<script type="text/javascript">
//<![CDATA[
if (typeof(Sys) === 'undefined') throw new Error('ASP.NET Ajax client-side framework failed to load.');
//]]>
</script>
<script src="/ScriptResource.axd?d=JnUc-DEDOM5KzzVKtsL1tZX1vXCIik-g0PLwVvE0nfwjt7419EYrrma0vWvtlIgMJIacy45CZJ0ziT3E4OUjVpQft6kfdyDFn6I-Or0SXsxfgVoejddIy8M8GfEdiwanxlP2Cb1f08PPpA_Milxoipx57ahf3KoCr5WF4nqbUaTsrz0Nh5CI6BoiIzkDnFix0&t=2a48f442" type="text/javascript"></script>
<script src="/ScriptResource.axd?d=pVdHczR8HTv0TYtXLibFoMacK_iVr2IKLNpgFc9mp9MVbITDUxa2Es3zeqeZTiZaBvQyqJBP0045kkr6ybgwH26ra8K1lAAvxX4VBLcNuQ-UrgbmHWscwazJNff9fqH-zik1EvL5yI3USehVLDhLSA2&t=ffffffffcfeeeb28" type="text/javascript"></script>
<script src="/ScriptResource.axd?d=LpGQnoKUSgO3ODsBUs8GfR17tdJPDF_fxASHtE6lHSOaqdhUm06NPsai70S3jU9mTu4lf88_RZNZevLL8qhkcnnNQ_Wxgr9o6Qi5vB6mvPFx9MsJW4CmJhWhqfTrCVU80&t=ffffffffcfeeeb28" type="text/javascript"></script>
<script src="/ScriptResource.axd?d=-qISl4-OkT-7X02E4FisrxgVK0rGCh1PBae27ZIWTPan87y4kqJrZJvydAb3Qniae3UQPaIYyzxewkvCnsp8-XkwdBGAhMecKSW7qwnWgRYvRKbC_zUA2sDymPCLG-jG0&t=ffffffffcfeeeb28" type="text/javascript"></script>
<script src="/ScriptResource.axd?d=VXG5HWKmJ5VfT6XbkUxKRifYbK9KIcXMhfLgGaKV9aOzuL33EaaCel7D7QJAWooXfYHW3XqzRPGMm_HIcB1R_nupFXA6zCeu8oQFgiKUWfzID2Osc9dsjC-u6QZNUWMK0&t=ffffffffcfeeeb28" type="text/javascript"></script>
<script src="/ScriptResource.axd?d=cvEEqfGZqjarfatJZ8QgyygvOEyJ2EDY_7UZh-WWr2y5e0MvPhGKmaVRX9WzFv81Cc67Lf6yFDFapy32PBlQ2JqH_PnnHrlxI9AUlZ2Jby4IZLtAWYjaGlQCyyjI58W20&t=ffffffffcfeeeb28" type="text/javascript"></script>
<script type="text/javascript">
//<![CDATA[
function WebForm_OnSubmit() {
if (typeof(ValidatorOnSubmit) == "function" && ValidatorOnSubmit() == false) return false;
return true;
}
//]]>
</script>
<script type="text/javascript">
//<![CDATA[
Sys.WebForms.PageRequestManager._initialize('ctl00$ScriptManager1', 'form1', [], [], [], 90, 'ctl00');
//]]>
</script>
<div id ="MainData">
<div id ="Header">Modify Chart Of Accounts</div>
<div id ="Menu">
<div id="PanelMenu">
<a href="Home.aspx">Home</a> | <a href="accountNumbers.aspx">Add New Account Numbers</a> | <a href="newlevels.aspx">Add New Levels</a>
</div>
</div>
<div id ="Content">
<div>
<table>
<tr>
<td>Totaling Level A</td>
<td>
<select name="ctl00$ContentPlaceHolder1$ddlTotalingLevelA" id="ContentPlaceHolder1_ddlTotalingLevelA" required="" style="width:250px;">
<option selected="selected" value=""></option>
</select>
<input type="hidden" name="ctl00$ContentPlaceHolder1$cdlTotalingLevelA_ClientState" id="ContentPlaceHolder1_cdlTotalingLevelA_ClientState" />
<span id="ContentPlaceHolder1_ddlARequired" title="ddlA is required." class="failureNotification" style="visibility:hidden;">*</span>
</td>
</tr>
<tr>
<td>Totaling Level B</td>
<td>
<select name="ctl00$ContentPlaceHolder1$ddlTotalingLevelB" id="ContentPlaceHolder1_ddlTotalingLevelB" style="width:250px;">
<option selected="selected" value=""></option>
</select>
<input type="hidden" name="ctl00$ContentPlaceHolder1$cdlTotalingLevelB_ClientState" id="ContentPlaceHolder1_cdlTotalingLevelB_ClientState" />
</td>
<td> </td>
<td> </td>
</tr>
<tr>
<td>Totaling Level C</td>
<td>
<select name="ctl00$ContentPlaceHolder1$ddlTotalingLevelC" id="ContentPlaceHolder1_ddlTotalingLevelC" style="width:250px;">
<option selected="selected" value=""></option>
</select>
<input type="hidden" name="ctl00$ContentPlaceHolder1$cdlTotalingLevelC_ClientState" id="ContentPlaceHolder1_cdlTotalingLevelC_ClientState" />
</td>
<td> </td>
<td> </td>
</tr>
<tr>
<td>Totaling Level D</td>
<td>
<select name="ctl00$ContentPlaceHolder1$ddlTotalingLevelD" id="ContentPlaceHolder1_ddlTotalingLevelD" style="width:250px;">
<option selected="selected" value=""></option>
</select>
<input type="hidden" name="ctl00$ContentPlaceHolder1$cdlTotalingLevelD_ClientState" id="ContentPlaceHolder1_cdlTotalingLevelD_ClientState" />
</td>
<td> </td>
<td> </td>
</tr>
<tr>
<td>Totaling Level E</td>
<td>
<select name="ctl00$ContentPlaceHolder1$ddlTotalingLevelE" id="ContentPlaceHolder1_ddlTotalingLevelE" style="width:250px;">
<option selected="selected" value=""></option>
</select>
<input type="hidden" name="ctl00$ContentPlaceHolder1$cdlTotalingLevelE_ClientState" id="ContentPlaceHolder1_cdlTotalingLevelE_ClientState" />
</td>
<td> </td>
<td> </td>
</tr>
<tr>
<td>Totaling Level F</td>
<td>
<select name="ctl00$ContentPlaceHolder1$ddlTotalingLevelF" id="ContentPlaceHolder1_ddlTotalingLevelF" style="width:250px;">
<option value=""></option>
</select>
<input type="hidden" name="ctl00$ContentPlaceHolder1$cdlTotalingLevelF_ClientState" id="ContentPlaceHolder1_cdlTotalingLevelF_ClientState" />
</td>
<td>
<input name="ctl00$ContentPlaceHolder1$txtTotalingLevel1" type="text" id="ContentPlaceHolder1_txtTotalingLevel1" required="" /></td>
<span id="ContentPlaceHolder1_txtFieldValidator" title="txtA is required." class="failureNotification" style="visibility:hidden;">*</span>
<td>
<input type="submit" name="ctl00$ContentPlaceHolder1$ButtonTotalingLevel" value="Add New Totaling Level" onclick="performCheck(); ;WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions("ctl00$ContentPlaceHolder1$ButtonTotalingLevel", "", true, "NewLevelValidationGroup", "", false, false))" id="ContentPlaceHolder1_ButtonTotalingLevel" /></td>
</tr>
</table>
</div>
</div>
<div id ="Footer">Copyright 2017 SP Global</div>
</div>
<script type="text/javascript">
//<![CDATA[
var Page_Validators = new Array(document.getElementById("ContentPlaceHolder1_ddlARequired"), document.getElementById("ContentPlaceHolder1_txtFieldValidator"));
//]]>
</script>
<script type="text/javascript">
//<![CDATA[
var ContentPlaceHolder1_ddlARequired = document.all ? document.all["ContentPlaceHolder1_ddlARequired"] : document.getElementById("ContentPlaceHolder1_ddlARequired");
ContentPlaceHolder1_ddlARequired.controltovalidate = "ContentPlaceHolder1_ddlTotalingLevelA";
ContentPlaceHolder1_ddlARequired.errormessage = "ddlA required.";
ContentPlaceHolder1_ddlARequired.validationGroup = "NewLevelValidationGroup";
ContentPlaceHolder1_ddlARequired.evaluationfunction = "RequiredFieldValidatorEvaluateIsValid";
ContentPlaceHolder1_ddlARequired.initialvalue = "";
var ContentPlaceHolder1_txtFieldValidator = document.all ? document.all["ContentPlaceHolder1_txtFieldValidator"] : document.getElementById("ContentPlaceHolder1_txtFieldValidator");
ContentPlaceHolder1_txtFieldValidator.controltovalidate = "ContentPlaceHolder1_txtTotalingLevel1";
ContentPlaceHolder1_txtFieldValidator.errormessage = "txtA required.";
ContentPlaceHolder1_txtFieldValidator.validationGroup = "NewLevelValidationGroup";
ContentPlaceHolder1_txtFieldValidator.evaluationfunction = "RequiredFieldValidatorEvaluateIsValid";
ContentPlaceHolder1_txtFieldValidator.initialvalue = "";
//]]>
</script>
<div class="aspNetHidden">
<input type="hidden" name="__VIEWSTATEGENERATOR" id="__VIEWSTATEGENERATOR" value="44FCCDDA" />
</div>
<script type="text/javascript">
//<![CDATA[
var Page_ValidationActive = false;
if (typeof(ValidatorOnLoad) == "function") {
ValidatorOnLoad();
}
function ValidatorOnSubmit() {
if (Page_ValidationActive) {
return ValidatorCommonOnSubmit();
}
else {
return true;
}
}
Sys.Application.add_init(function() {
$create(Sys.Extended.UI.CascadingDropDownBehavior, {"ClientStateFieldID":"ContentPlaceHolder1_cdlTotalingLevelA_ClientState","category":"TOTALING_LEVEL_A","id":"ContentPlaceHolder1_cdlTotalingLevelA","loadingText":"Loading...","promptText":"Select Totaling Level A","serviceMethod":"GetLevelAList","servicePath":"ServiceCS.asmx"}, null, null, $get("ContentPlaceHolder1_ddlTotalingLevelA"));
});
document.getElementById('ContentPlaceHolder1_ddlARequired').dispose = function() {
Array.remove(Page_Validators, document.getElementById('ContentPlaceHolder1_ddlARequired'));
}
Sys.Application.add_init(function() {
$create(Sys.Extended.UI.CascadingDropDownBehavior, {"ClientStateFieldID":"ContentPlaceHolder1_cdlTotalingLevelB_ClientState","category":"TOTALING_LEVEL_B","id":"ContentPlaceHolder1_cdlTotalingLevelB","loadingText":"Loading...","parentControlID":"ContentPlaceHolder1_ddlTotalingLevelA","promptText":"Select Totaling Level B","serviceMethod":"GetLevelBList","servicePath":"ServiceCS.asmx"}, null, null, $get("ContentPlaceHolder1_ddlTotalingLevelB"));
});
Sys.Application.add_init(function() {
$create(Sys.Extended.UI.CascadingDropDownBehavior, {"ClientStateFieldID":"ContentPlaceHolder1_cdlTotalingLevelC_ClientState","category":"TOTALING_LEVEL_C","id":"ContentPlaceHolder1_cdlTotalingLevelC","loadingText":"Loading...","parentControlID":"ContentPlaceHolder1_ddlTotalingLevelB","promptText":"Select Totaling Level C","serviceMethod":"GetLevelCList","servicePath":"ServiceCS.asmx"}, null, null, $get("ContentPlaceHolder1_ddlTotalingLevelC"));
});
Sys.Application.add_init(function() {
$create(Sys.Extended.UI.CascadingDropDownBehavior, {"ClientStateFieldID":"ContentPlaceHolder1_cdlTotalingLevelD_ClientState","category":"TOTALING_LEVEL_D","id":"ContentPlaceHolder1_cdlTotalingLevelD","loadingText":"Loading...","parentControlID":"ContentPlaceHolder1_ddlTotalingLevelC","promptText":"Select Totaling Level D","serviceMethod":"GetLevelDList","servicePath":"ServiceCS.asmx"}, null, null, $get("ContentPlaceHolder1_ddlTotalingLevelD"));
});
Sys.Application.add_init(function() {
$create(Sys.Extended.UI.CascadingDropDownBehavior, {"ClientStateFieldID":"ContentPlaceHolder1_cdlTotalingLevelE_ClientState","category":"TOTALING_LEVEL_E","id":"ContentPlaceHolder1_cdlTotalingLevelE","loadingText":"Loading...","parentControlID":"ContentPlaceHolder1_ddlTotalingLevelD","promptText":"Select Totaling Level E","serviceMethod":"GetLevelEList","servicePath":"ServiceCS.asmx"}, null, null, $get("ContentPlaceHolder1_ddlTotalingLevelE"));
});
Sys.Application.add_init(function() {
$create(Sys.Extended.UI.CascadingDropDownBehavior, {"ClientStateFieldID":"ContentPlaceHolder1_cdlTotalingLevelF_ClientState","category":"TOTALING_LEVEL_F","id":"ContentPlaceHolder1_cdlTotalingLevelF","loadingText":"Loading...","parentControlID":"ContentPlaceHolder1_ddlTotalingLevelE","serviceMethod":"GetLevelFList","servicePath":"ServiceCS.asmx"}, null, null, $get("ContentPlaceHolder1_ddlTotalingLevelF"));
});
document.getElementById('ContentPlaceHolder1_txtFieldValidator').dispose = function() {
Array.remove(Page_Validators, document.getElementById('ContentPlaceHolder1_txtFieldValidator'));
}
//]]>
</script>
</form>
<!-- Visual Studio Browser Link -->
<script type="application/json" id="__browserLink_initializationData">
{"appName":"Internet Explorer","requestId":"1ba9c1de159f4a2098bffaed87c6be97"}
</script>
<script type="text/javascript" src="http://localhost:58780/16c72213dce7450fa950e42b73e9abbd/browserLink" async="async"></script>
<!-- End Browser Link -->
</body>
</html>
ASKER
I also tried the ids as follows and still get null:
function performCheck() {
Page_ClientValidate("NewLevelValidationGroup");
var textBox = document.getElementById('<%= ContentPlaceHolder1_txtFieldValidator.ClientID %>');
var ddl = document.getElementById('<%= ContentPlaceHolder1_ddlARequired.ClientID %>');
//alert("textBox "+textBox);
//alert("ddl "+ddl);
if (Page_IsValid) {
//return confirm("Are you sure you want to add " );
return confirm("Are you sure you want to add " + textBox + " under " + ddl);
}
}
ASKER
Are you going to charge as live consultant? I think that is the new feature, I never used before?
Sorry . . . the issue is due to the fact that the javascript is in an external file. That won't process the server tags (EG: <%= %>) so that's not getting processed.
Your options are to
1) hardcode the value in the external javascript tag:
2) Pass a reference to the control in the function:
or
3) create a global variable and then use it in the javascript:
aspx Page
js file:
Your options are to
1) hardcode the value in the external javascript tag:
var textBox = document.getElementById('ContentPlaceHolder1_txtTotalingLevel1');
2) Pass a reference to the control in the function:
function Validate(textbox,ddl){ }
or
3) create a global variable and then use it in the javascript:
aspx Page
<script>
var textBox = document.getElementyById('<%= txtTotalingLevel1.ClientID %>'
</script>
js file:
alert(textBox);
ASKER
I tried the global variable option. Now I get runtime error: 0x800a1391 - JavaScript runtime error: 'textBox' is undefined
I added the following to the aspx file:
I added the following to the aspx file:
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
<script src="jquery-1.7.2.js" type="text/javascript"></script>
<script src="JavaScriptValidations.js">
var textBox = document.getElementyById('<%= txtTotalingLevel1.ClientID %>'
var ddl = document.getElementyById('<%= ddlTotalingLevelA.ClientID %>'
</script>
</asp:Content>
and here is my js file:
function performCheck() {
Page_ClientValidate("NewLevelValidationGroup");
//var ddl = document.getElementById("ddlTotalingLevelA").options[document.getElementById("ddlTotalingLevelA").selectedIndex].value;
//var textBox = document.getElementById('<%= ContentPlaceHolder1_txtFieldValidator.ClientID %>');
//var ddl = document.getElementById('<%= ContentPlaceHolder1_ddlARequired.ClientID %>');
alert("textBox "+textBox);
alert("ddl "+ddl);
if (Page_IsValid) {
//return confirm("Are you sure you want to add " );
return confirm("Are you sure you want to add " + textBox + " under " + ddl);
}
}
ASKER
I added the javascript function on the aspx page. Now when I click the button, I get the following:
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
<script src="jquery-1.7.2.js" type="text/javascript"></script>
<script>
function performCheck() {
Page_ClientValidate("NewLevelValidationGroup");
//var ddl = document.getElementById("ddlTotalingLevelA").options[document.getElementById("ddlTotalingLevelA").selectedIndex].value;
var textBox = document.getElementById('<%= txtFieldValidator.ClientID %>');
var ddl = document.getElementById('<%= ddlTotalingLevelA.ClientID %>');
alert("textBox "+textBox);
alert("ddl "+ddl);
if (Page_IsValid) {
return confirm("Are you sure you want to add " + textBox + " under " + ddl);
}
}
</script>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks. Now it captures the correct values of the drop down list, but the cancel button does not work as cancel. It still goes on to execute the command, regardless of weather I hit ok or cancel. OK ans Cancel was working when I originally started in the javascript file.
OnClientClick ="return performCheck(); "
ASKER
Its working now. Thanks. I editied the if else on javascript to explicitly return false
glad you got it working.
ASKER
Kyle, Thanks a lot for your help.
try post your codes here