Lisa412
asked on
Javascript function undefined...but it is!
I can't believe something this simple could be so difficult!
I have an asp page that I am using as a custom dialog box to request a password. Here is the HMTL:
Since I could not get any response out of the OK or Cancel buttons when their HTML included an OnClientClicked tag, I added the following to the code behind in the page load event.
When I click either the OK or the Cancel buttons, I get an error that says the javascript function returnArg or closeAndCancel is undefined. And yet I've been staring at the definition for hours!
Can someone please tell me what is wrong?
At one point, it was responding to the OK button but then saying that txtInput was undefined in the third line of that function. Somehow in trying to fix that, I managed to break it completely.
I have an asp page that I am using as a custom dialog box to request a password. Here is the HMTL:
<body>
<form id="form2" runat="server">
<telerik:RadScriptManager ID="RadScriptManager2" runat="server">
<Scripts>
<asp:ScriptReference Assembly="Telerik.Web.UI"
Name="Telerik.Web.UI.Common.Core.js">
</asp:ScriptReference>
<asp:ScriptReference Assembly="Telerik.Web.UI"
Name="Telerik.Web.UI.Common.jQuery.js">
</asp:ScriptReference>
<asp:ScriptReference Assembly="Telerik.Web.UI"
Name="Telerik.Web.UI.Common.jQueryInclude.js">
</asp:ScriptReference>
</Scripts>
</telerik:RadScriptManager>
<script language="javascript" type="text/javascript">
function GetRadWindow() {
var oWindow = null;
if (window.radWindow)
oWindow = window.radWindow;
else if (window.frameElement.radWindow)
oWindow = window.frameElement.radWindow;
return oWindow;
}
function cancelAndClose() {
var oWindow = GetRadWindow();
oWindow.close(null);
}
function returnArg() {
var oWnd = GetRadWindow();
var txtInput = document.getElementById("<%=txtPW.ClientID %>");
oWnd.close(txtinput.text);
}
</script>
<asp:Label ID="Label1" runat="server" Text="Label"> </asp:Label>
<telerik:RadTextBox ID="RadTextBox1" runat="server" TextMode="Password"> </telerik:RadTextBox>
<telerik:RadButton ID="RadButton1" runat="server" Text="OK" Width = "100px" > </telerik:RadButton>
     
<telerik:RadButton ID="RadButton2" runat="server" Text="Cancel" Width = "100px" > </telerik:RadButton>
</form>
</body>
Since I could not get any response out of the OK or Cancel buttons when their HTML included an OnClientClicked tag, I added the following to the code behind in the page load event.
btnOK.Attributes.Add("language", "javascript")
btnOK.Attributes.Add("OnClick", "returnArg();")
btnCancel.Attributes.Add("language", "javascript")
btnCancel.Attributes.Add("OnClick", "cancelAndClose();")
When I click either the OK or the Cancel buttons, I get an error that says the javascript function returnArg or closeAndCancel is undefined. And yet I've been staring at the definition for hours!
Can someone please tell me what is wrong?
At one point, it was responding to the OK button but then saying that txtInput was undefined in the third line of that function. Somehow in trying to fix that, I managed to break it completely.
ASKER
Hi - I hope this is what you're looking for. Thanks for your help.
<!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><title>
</title><link href="/WebResource.axd?d=Azr25rlxcj2oD8DG4LLTwatHTpAsPojhwLtPYXcU6i4mHdD74H8zIgLltDeX2TXT2bD35pIy9Iq0PTEXjkKv3EL2-o6jVRvklm8FjrXiho_3WUbdpyxShxxhA8suB5yQNTzYfxiU3ztflDGUf9tV0Q2&t=635173546100000000" type="text/css" rel="stylesheet" class="Telerik_stylesheet" /><link href="/WebResource.axd?d=j1E0mRB4jBNXNuCEKsdtNcXpCqQROTHUJV7yhsntKkarCRiYgnMwZ8T1Uf15BZn26FX6znOsJ90n_V-zT62zeLEn6hCF3UnhcJce5-mdS5HoCs5P7HIBX0InEWmchhWMvq9zyUpAPubt8VyvES8YMheAaKL-e9hULh7g1cTDU9g1&t=635173546100000000" type="text/css" rel="stylesheet" class="Telerik_stylesheet" /><link href="/WebResource.axd?d=7E6yD7MJcLYPnajMz3T6lwN5wLdWuSBRDCVWA-3ouS17Q3Y_R8JTSa8dF9RDt9i5apBj4EVqAkJfb-ytLe_0rNE6T5QHCxEPmsRbqSdEXaMyejiiow6WAkSrS_sPbApH51TRm5ljQ-ISv0eKQVbstQ2&t=635173546100000000" type="text/css" rel="stylesheet" class="Telerik_stylesheet" /><link href="/WebResource.axd?d=9PGENFqWbEx-jn1IhpzbdjWPqCqDCKNYhkCXWot7E7n1djmnWuX_bfDr1Lpz8cc3_DX83IjqA78CD_jMgAP4ScE4zmgyFeZR3tdtv-sOtR6ypQqD15Q9D-7jCy3jCTzDIbVdGWi7YVqiGEzeMFvHkdjnRzTLUrTl-fxp2PD2-441&t=635173546100000000" type="text/css" rel="stylesheet" class="Telerik_stylesheet" /></head>
<body>
<form method="post" action="dlgPassword.aspx" id="form1">
<div class="aspNetHidden">
<input type="hidden" name="RadScriptManager1_TSM" id="RadScriptManager1_TSM" value="" />
<input type="hidden" name="__EVENTTARGET" id="__EVENTTARGET" value="" />
<input type="hidden" name="__EVENTARGUMENT" id="__EVENTARGUMENT" value="" />
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwUJOTA2NTEwNzA2D2QWAgIDD2QWCAIBDw8WAh4EVGV4dAXbAVRoaXMgYmxlbmQgY2FuIG5vdCBiZSByZWxlYXNlZCB3aXRob3V0IG1hbmFnZW1lbnQgYXBwcm92YWwgYmVjYXVzZSBub3QgYWxsIHZhbHVlcyBhcmUgd2l0aGluIHNwZWNpZmllZCBsaW1pdHMuDQpJZiB5b3UgYXJlIGEgbWFuYWdlciBhbmQgd2lzaCB0byBvdmVycmlkZSB0aGlzIHByb2hpYml0aW9uIGFuZCByZWxlYXNlIHRoZSBibGVuZCwgZW50ZXIgeW91ciBwYXNzd29yZCBoZXJlLmRkAgIPFCsACA8WBB4XRW5hYmxlQWpheFNraW5SZW5kZXJpbmdoHg1MYWJlbENzc0NsYXNzBQdyaUxhYmVsZBYIHgVXaWR0aBsAAAAAAABkQAEAAAAeClJlc2l6ZU1vZGULKXNUZWxlcmlrLldlYi5VSS5SZXNpemVNb2RlLCBUZWxlcmlrLldlYi5VSSwgVmVyc2lvbj0yMDEzLjMuMTAxNS40MCwgQ3VsdHVyZT1uZXV0cmFsLCBQdWJsaWNLZXlUb2tlbj0xMjFmYWU3ODE2NWJhM2Q0AB4IQ3NzQ2xhc3MFEXJpVGV4dEJveCByaUhvdmVyHgRfIVNCAoICFggfAxsAAAAAAABkQAEAAAAfBAsrBAAfBQURcmlUZXh0Qm94IHJpRXJyb3IfBgKCAhYIHwMbAAAAAAAAZEABAAAAHwQLKwQAHwUFE3JpVGV4dEJveCByaUZvY3VzZWQfBgKCAhYIHwQLKwQAHwMbAAAAAAAAZEABAAAAHwUFE3JpVGV4dEJveCByaUVuYWJsZWQfBgKCAhYIHwMbAAAAAAAAZEABAAAAHwQLKwQAHwUFFHJpVGV4dEJveCByaURpc2FibGVkHwYCggIWCB8DGwAAAAAAAGRAAQAAAB8ECysEAB8FBRFyaVRleHRCb3ggcmlFbXB0eR8GAoICFggfAxsAAAAAAABkQAEAAAAfBAsrBAAfBQUQcmlUZXh0Qm94IHJpUmVhZB8GAoICZAIDDzwrAAQBAA8WAh8BaBYEHghsYW5ndWFnZQUKamF2YXNjcmlwdB4HT25DbGljawUMcmV0dXJuQXJnKCk7ZAIEDzwrAAQBAA8WAh8BaBYEHwcFCmphdmFzY3JpcHQfCAURY2FuY2VsQW5kQ2xvc2UoKTtkGAEFHl9fQ29udHJvbHNSZXF1aXJlUG9zdEJhY2tLZXlfXxYCBQVidG5PSwUJYnRuQ2FuY2VsmyQ+gFxa+JU6v7SZEtj27AEDxlTG0RX8gGo9kzi8m24=" />
</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=pvqVPH_l3-wuvhSo7QBVaOeKKzvKeeHjG4_kjkNChtk4YPO_AKtbuTtovnx1sJnWF9HdrccMyzDDGON7gx8xgNZ9kY73m4z3kOphcOL5-6U1&t=635194247536870992" type="text/javascript"></script>
<script src="/Telerik.Web.UI.WebResource.axd?_TSM_HiddenField_=RadScriptManager1_TSM&compress=1&_TSM_CombinedScripts_=%3b%3bSystem.Web.Extensions%2c+Version%3d4.0.0.0%2c+Culture%3dneutral%2c+PublicKeyToken%3d31bf3856ad364e35%3aen-US%3af01b1325-3d40-437a-8da2-df3d86714220%3aea597d4b%3ab25378d2%3bTelerik.Web.UI%3aen-US%3aac331549-681c-4402-9fb7-09ec3c579ee8%3a16e4e7cd%3af7645509%3a22a6274a%3ab7778d6c%3a24ee1bba%3a7165f74" 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>
<div class="aspNetHidden">
<input type="hidden" name="__EVENTVALIDATION" id="__EVENTVALIDATION" value="/wEWCALq8cCDDgK9+8qeDgLdkpmPAQLw/dj7DwLdkpmPAQKQ9M/rBQK9m46fCwKQ9M/rBTZZsNxpToeFAazy0EwZQhJA3hzaQawxVtwp7vETmktj" />
</div>
<script type="text/javascript">
//<![CDATA[
Sys.WebForms.PageRequestManager._initialize('RadScriptManager1', 'form1', [], [], [], 90, '');
//]]>
</script>
<script language="javascript" type="text/javascript">
function GetRadWindow() {
var oWindow = null;
if (window.radWindow)
oWindow = window.radWindow;
else if (window.frameElement.radWindow)
oWindow = window.frameElement.radWindow;
return oWindow;
}
function cancelAndClose() {
var oWindow = GetRadWindow();
oWindow.close(null);
}
function returnArg() {
var oWnd = GetRadWindow();
var txtInput = document.getElementById("txtPW");
oWnd.close(txtinput.text);
}
</script>
<span id="lblPW">This blend can not be released without management approval because not all values are within specified limits.
If you are a manager and wish to override this prohibition and release the blend, enter your password here.</span>
<br />
<br />
<!-- 2013.3.1015.40 --><span id="txtPW_wrapper" class="riSingle RadInput RadInput_WebBlue" style="width:160px;"><input id="txtPW" name="txtPW" size="20" class="riTextBox riEnabled" type="password" /><input id="txtPW_ClientState" name="txtPW_ClientState" type="hidden" /></span>
<br />
<br />
<span id="btnOK" class="RadButton RadButton_WebBlue rbSkinnedButton" language="javascript" OnClick="returnArg();" style="display:inline-block;width:100px;"><input class="rbDecorated" type="submit" name="btnOK_input" id="btnOK_input" value="OK" style="width:100%;padding-left:0;padding-right:0;padding-left:4px;" /><input id="btnOK_ClientState" name="btnOK_ClientState" type="hidden" /></span>
     
<span id="btnCancel" class="RadButton RadButton_WebBlue rbSkinnedButton" language="javascript" OnClick="cancelAndClose();" style="display:inline-block;width:100px;"><input class="rbDecorated" type="submit" name="btnCancel_input" id="btnCancel_input" value="Cancel" style="width:100%;padding-left:0;padding-right:0;padding-left:4px;" /><input id="btnCancel_ClientState" name="btnCancel_ClientState" type="hidden" /></span>
<script type="text/javascript">
//<![CDATA[
Sys.Application.add_init(function() {
$create(Telerik.Web.UI.RadTextBox, {"_focused":false,"_postBackEventReferenceScript":"setTimeout(\"__doPostBack(\\\u0027txtPW\\\u0027,\\\u0027\\\u0027)\", 0)","_skin":"WebBlue","clientStateFieldID":"txtPW_ClientState","enabled":true,"styles":{HoveredStyle: ["width:160px;", "riTextBox riHover"],InvalidStyle: ["width:160px;", "riTextBox riError"],DisabledStyle: ["width:160px;", "riTextBox riDisabled"],FocusedStyle: ["width:160px;", "riTextBox riFocused"],EmptyMessageStyle: ["width:160px;", "riTextBox riEmpty"],ReadOnlyStyle: ["width:160px;", "riTextBox riRead"],EnabledStyle: ["width:160px;", "riTextBox riEnabled"]}}, null, null, $get("txtPW"));
});
Sys.Application.add_init(function() {
$create(Telerik.Web.UI.RadButton, {"_accessKey":"","_postBackReference":"","clientStateFieldID":"btnOK_ClientState","iconData":{},"imageData":{},"text":"OK","toggleStatesData":[],"uniqueGroupName":"","uniqueID":"btnOK","width":"100px"}, null, null, $get("btnOK"));
});
Sys.Application.add_init(function() {
$create(Telerik.Web.UI.RadButton, {"_accessKey":"","_postBackReference":"","clientStateFieldID":"btnCancel_ClientState","iconData":{},"imageData":{},"text":"Cancel","toggleStatesData":[],"uniqueGroupName":"","uniqueID":"btnCancel","width":"100px"}, null, null, $get("btnCancel"));
});
//]]>
</script>
</form>
</body>
</html>
Does it work wit hthe following :
btnOK.Attributes.Add("language", "javascript")
btnOK.Attributes.Add("OnClick", "if(window.radWindow) oWnd=window.radWindow;else if(window.frameElement.radWindow) oWnd=window.frameElement.radWindow;else alert('null');var txtInput = document.getElementById('txtPW');oWnd.close(txtinput.text);")
btnCancel.Attributes.Add("language", "javascript")
btnCancel.Attributes.Add("OnClick", "if(window.radWindow) oWnd=window.radWindow;else if(window.frameElement.radWindow) oWnd=window.frameElement.radWindow;else alert('null');oWnd.close(null);")
ASKER
The suggested code is close. When run, it says that txtInput is not defined. So I modified your 2nd line to eliminate the var txtInput as follows:
btnOK.Attributes.Add("OnCl ick", "if(window.radWindow) oWnd=window.radWindow;else if(window.frameElement.rad Window) oWnd=window.frameElement.r adWindow;e lse alert('null');oWnd.close(d ocument.ge tElementBy Id('txtPW' ).text);")
This actually runs but it is not passing back the value in txtPW to the calling page. When I put a breakpoint in the callback function, it says the value is {object Object}. (which is where I was several iterations ago).
The HMTL on the page which opens this password window is:
As you can see, the onclientclose event for this window should be handled by the javascript function dlgPWClose. It should put the returned value in the hidden field HiddenReleasePassword and then essentially "click" the btnReleaseCallBack. This appears to be working because I put a breakpoint in the code behind for btnReleaseCallBack and it does hit it. However, the value it has for HiddenReleasePassword is {object Object}.
So how do I get the password return value back?
Thanks again for helping.
btnOK.Attributes.Add("OnCl
This actually runs but it is not passing back the value in txtPW to the calling page. When I put a breakpoint in the callback function, it says the value is {object Object}. (which is where I was several iterations ago).
The HMTL on the page which opens this password window is:
<script language="javascript" type="text/javascript">
function dlgPWClose(sender, args)
{
document.getElementById("<%=HiddenReleasePassword.ClientID%>").value = args;
<%=ClientScript.GetPostBackEventReference(new System.Web.UI.PostBackOptions(btnReleaseCallBack))%> ;
}
</script>
<telerik:RadWindowManager ID="RadWindowManager1" runat="server" Skin="WebBlue">
<Windows>
<telerik:RadWindow ID="rwPassword" runat="server" Modal="true"
NavigateUrl="~/UserPages/dlgPassword.aspx" Height = "200px" Width = "1200px"
Title="Blend Composition Outside of Limits" Behaviors="Close, Move" Behavior="Close, Move"
onclientclose = "dlgPWClose">
</telerik:RadWindow>
</Windows>
</telerik:RadWindowManager>
As you can see, the onclientclose event for this window should be handled by the javascript function dlgPWClose. It should put the returned value in the hidden field HiddenReleasePassword and then essentially "click" the btnReleaseCallBack. This appears to be working because I put a breakpoint in the code behind for btnReleaseCallBack and it does hit it. However, the value it has for HiddenReleasePassword is {object Object}.
So how do I get the password return value back?
Thanks again for helping.
The HMTL on the page which opens this password window is
with your web browser, once you the page or popup window opened with this content, do a right click on the page and choose view source, try to locate this part and post it here
Is the function radWindow defined or not...?
No, to have more chanceto locate it, put a div around with a specific ID attribute :
<div id="toLocate_RadWindow">
<telerik:RadWindowManager ID="RadWindowManager1" runat="server" Skin="WebBlue">
<Windows>
<telerik:RadWindow ID="rwPassword" runat="server" Modal="true"
NavigateUrl="~/UserPages/dlgPassword.aspx" Height = "200px" Width = "1200px"
Title="Blend Composition Outside of Limits" Behaviors="Close, Move" Behavior="Close, Move"
onclientclose = "dlgPWClose">
</telerik:RadWindow>
</Windows>
</telerik:RadWindowManager>
</div>
ASKER
Here is the relevant rendition, I hope. Please note there is another window on the page "rwAddSelect" which is not giving me any trouble so I did not include in prior code. But I didn't want to excise it out of this code because I was afraid I would make a mess of it.
<div id="toLocate_RadWindow">
<div id="ctl00_MainContent_RadWindowManager1" style="display:none;">
<div id="ctl00_MainContent_rwAddSelect" style="display:none;">
<div id="ctl00_MainContent_rwAddSelect_C" style="display:none;">
</div><input id="ctl00_MainContent_rwAddSelect_ClientState" name="ctl00_MainContent_rwAddSelect_ClientState" type="hidden" />
</div><div id="ctl00_MainContent_rwPassword" style="display:none;">
<div id="ctl00_MainContent_rwPassword_C" style="display:none;">
</div><input id="ctl00_MainContent_rwPassword_ClientState" name="ctl00_MainContent_rwPassword_ClientState" type="hidden" />
</div><div id="ctl00_MainContent_RadWindowManager1_alerttemplate" style="display:none;">
<div class="rwDialogPopup radalert">
<div class="rwDialogText">
{1}
</div>
<div>
<a onclick="$find('{0}').close(true);"
class="rwPopupButton" href="javascript:void(0);">
<span class="rwOuterSpan">
<span class="rwInnerSpan">##LOC[OK]##</span>
</span>
</a>
</div>
</div>
</div><div id="ctl00_MainContent_RadWindowManager1_prompttemplate" style="display:none;">
<div class="rwDialogPopup radprompt">
<div class="rwDialogText">
{1}
</div>
<div>
<script type="text/javascript">
function RadWindowprompt_detectenter(id, ev, input)
{
if (!ev) ev = window.event;
if (ev.keyCode == 13)
{
var but = input.parentNode.parentNode.getElementsByTagName("A")[0];
if (but)
{
if (but.click) but.click();
else if (but.onclick)
{
but.focus(); var click = but.onclick; but.onclick = null; if (click) click.call(but);
}
}
return false;
}
else return true;
}
</script>
<input title="Enter Value" onkeydown="return RadWindowprompt_detectenter('{0}', event, this);" type="text" class="rwDialogInput" value="{2}" />
</div>
<div>
<a onclick="$find('{0}').close(this.parentNode.parentNode.getElementsByTagName('input')[0].value);"
class="rwPopupButton" href="javascript:void(0);" ><span class="rwOuterSpan"><span class="rwInnerSpan">##LOC[OK]##</span></span></a>
<a onclick="$find('{0}').close(null);" class="rwPopupButton" href="javascript:void(0);"><span class="rwOuterSpan"><span class="rwInnerSpan">##LOC[Cancel]##</span></span></a>
</div>
</div>
</div><div id="ctl00_MainContent_RadWindowManager1_confirmtemplate" style="display:none;">
<div class="rwDialogPopup radconfirm">
<div class="rwDialogText">
{1}
</div>
<div>
<a onclick="$find('{0}').close(true);" class="rwPopupButton" href="javascript:void(0);" ><span class="rwOuterSpan"><span class="rwInnerSpan">##LOC[OK]##</span></span></a>
<a onclick="$find('{0}').close(false);" class="rwPopupButton" href="javascript:void(0);"><span class="rwOuterSpan"><span class="rwInnerSpan">##LOC[Cancel]##</span></span></a>
</div>
</div>
</div><input id="ctl00_MainContent_RadWindowManager1_ClientState" name="ctl00_MainContent_RadWindowManager1_ClientState" type="hidden" />
</div>
</div>
There's no field with this ID : txtPW
This is the issue, where is this field ?
This is the issue, where is this field ?
ASKER
txtPW is defined on the dialog window. It's text value should be passed back to the calling page as an argument. I don't see any reference to txtPW in the prior code - where did you see its ID?
ASKER
Even though everything I have googled suggests that I should be able to pass parameters to and from this custom dialog page, I am thinking perhaps I should just abandon this attempt and set the password as a Session variable on the dialog page, close that page, and then retrieve the password from the Session variable on the calling page.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
And the code behind on calling page on the hidden btnReleaseCallBack which is called when the dialog window closes is:
Private Sub btnReleaseCallBack_Click(sender As Object, e As System.EventArgs) Handles btnReleaseCallBack.Click
Dim strPWOverride As String = ""
Try
strPWOverride = Session("PWOverride")
Catch
strPWOverride = ""
End Try
If strPWOverride = "" Then
Exit Sub
End If
Try
'Validate password belongs to someone with Lab Manager privileges
Dim blnValid As Boolean = IsLabManagerPassword(strPWOverride)
If blnValid Then
ReleaseBlend()
Else
RadWindowManager1.RadAlert("ERROR: Invalid password. \n Can not release out of spec blend.", 600, 200, "Invalid Password", "")
End If
Catch ex As Exception
ShowAlert(Page, ex.InnerException.Message)
End Try
HiddenReleasePassword.Value = ""
End Sub
ASKER
This is the final solution to my exact problem. The expert helped me find the way there.
If we find an error in the rendered html, then you can go back to the asp code and figure out where to change it. For now, let's see your rendered html and js/jquery.