Popup window passes value to opener but not recognized

T

Timo

I created this application using ASP.NET 1.0 and it has worked great
for several years. I recently upgraded to 2.0 and now this isn't
working:

I have a popup window that indicates to the user a problem. They have
several choices, in all of them I change the value of items on the
opener window like so:


window.opener.document.getElementById('txtFunctionError').value='Confirm';
window.opener.document.Form1.submit();
window.opener.focus();
window.close();

In debuging the application I can SEE that the form value has been
changed to "Confirm" however in the postback code behind where I do a
Request.Form("txtFunctionError") the value is not changing.

What is the deal with that?

Like I said, this had been working perfectly for several years and now
all of a sudden it doesn't. The Version of IE hasn't changed, it just
seems that the Code cannot retrieve the form items current value, the
value remains what it was before the popup, yet I can see that the
value was changed on the web page.
 
A

Alexey Smirnov

I created this application using ASP.NET 1.0 and it has worked great
for several years.  I recently upgraded to 2.0 and now this isn't
working:

I have a popup window that indicates to the user a problem.  They have
several choices, in all of them I change the value of items on the
opener window like so:

window.opener.document.getElementById('txtFunctionError').value='Confirm';
  window.opener.document.Form1.submit();
  window.opener.focus();
  window.close();

In debuging the application I can SEE that the form value has been
changed to "Confirm" however in the postback code behind where I do a
Request.Form("txtFunctionError") the value is not changing.

What is the deal with that?

Like I said, this had been working perfectly for several years and now
all of a sudden it doesn't.  The Version of IE hasn't changed, it just
seems that the Code cannot retrieve the form items current value, the
value remains what it was before the popup, yet I can see that the
value was changed on the web page.

If txtFunctionError is the server control then you should change your
script to

getElementById("<%=txtFunctionError.ClientID%>")

where ClientID returns the server control identifier generated by
ASP.NET.
 
T

Timo

Alexey,

Thank you for your response. I am registering a client script block
for my javascript so the inline write <%=%> doesn't work for me. Here
is a larger example of my code:

Dim sb As New System.Text.StringBuilder
sb.Append("<script language=""javascript"">" & vbCrLf)
sb.Append("var blnClose = true;" & vbCrLf)
sb.Append("function fnPostBack() {" & vbCrLf)
Select Case strControlName
Case "Save"
' Set Openers control values to call Confirm(True)
sb.Append("
window.opener.document.getElementById('" & txtFunctionError.ClientID &
"').value='Confirm';" & vbCrLf)
sb.Append("
window.opener.document.Form1.submit();" & vbCrLf)
sb.Append(" window.opener.focus();" & vbCrLf)
sb.Append(" window.close();" & vbCrLf)
sb.Append(" blnClose = false;" & vbCrLf)
Case "Retry"
' Reset Openers control values to call
ReInitializeTagControls
sb.Append("
window.opener.document.getElementById('txtFunctionName').value='HeadPost';"
& vbCrLf)
sb.Append("
window.opener.document.getElementById('txtPositionInFunction').value =
'0';" & vbCrLf)
sb.Append("
window.opener.document.getElementById('txtFunctionError').value='Retry';"
& vbCrLf)
sb.Append("
window.opener.document.Form1.submit();" & vbCrLf)
sb.Append(" window.opener.focus();" & vbCrLf)
sb.Append(" window.close();" & vbCrLf)
sb.Append(" blnClose = false;" & vbCrLf)
Case "Reject"
' Reset Openers control values to call
ReInitialize
sb.Append("
window.opener.document.getElementById('txtFunctionName').value='';" &
vbCrLf)
sb.Append("
window.opener.document.getElementById('txtPositionInFunction').value =
'0';" & vbCrLf)
sb.Append("
window.opener.document.getElementById('txtFunctionError').value='Reject';"
& vbCrLf)
sb.Append("
window.opener.document.Form1.submit();" & vbCrLf)
sb.Append(" window.opener.focus();" & vbCrLf)
sb.Append(" window.close();" & vbCrLf)
sb.Append(" blnClose = false;" & vbCrLf)
Case Else
sb.Append("
document.getElementById('cmdSave').focus();" & vbCrLf)
End Select
sb.Append("}" & vbCrLf)

Me.cmdRetry.Attributes("onclick") = "blnClose = false;"
Me.cmdCancel.Attributes("onclick") = "blnClose = false;"
Me.cmdSave.Attributes("onclick") = "blnClose = false;"

' Query String to pass a call for ReInitializeTagControls
sb.Append("function fnWindowClose(){" & vbCrLf)
sb.Append(" if(blnClose){" & vbCrLf)
sb.Append("
window.opener.document.getElementById('txtFunctionName').value='HeadPost';"
& vbCrLf)
sb.Append("
window.opener.document.getElementById('txtPositionInFunction').value =
'0';" & vbCrLf)
sb.Append("
window.opener.document.getElementById('txtFunctionError').value='Retry';"
& vbCrLf)
sb.Append(" window.opener.document.Form1.submit();" &
vbCrLf)
sb.Append(" window.opener.focus();" & vbCrLf)
sb.Append(" window.close();" & vbCrLf)
sb.Append(" }" & vbCrLf)
sb.Append("}" & vbCrLf)

sb.Append("</script>" & vbCrLf)
ClientScript.RegisterClientScriptBlock(Me.GetType(),
"ClientScripts", sb.ToString)
 
A

Alexey Smirnov

Alexey,

Thank you for your response.  I am registering a client script block
for my javascript so the inline write <%=%> doesn't work for me.  Here
is a larger example of my code:

okay, I see that you change it correct

window.opener.document.getElementById('" &
txtFunctionError.ClientID...

and if it doesn't help, try to debug the script.

For example, add some test alert boxes to see what happens there, e.g.

sb.Append("alert(window.opener.document.getElementById('" _
& txtFunctionError.ClientID & "'));");

if object has been found it would return [object] or something like
this, otherwise [null]
 
T

Timo

Alexey,

The main problem is that txtFunctionError is a control that exists on
the main window, not the popup. The popup is attempting to change the
value of the control on the main window and then closes itself. I
tested the value of txtFunctionError.ClientID and it returns
"txtFunctionError". I used a Session variable to hold the value of
txtFunctionError.ClientID and then write it to the javascript script
block I am appending. I cannot reference the control on the main
window from the popup window using code behind (asp.net language).

So here is what I did to debug the script as you asked:

sb.Append("
alert(window.opener.document.getElementById('" &
Session("txtFunctionError") & "').value);" & vbCrLf)
sb.Append("
window.opener.document.getElementById('" & Session("txtFunctionError")
& "').value='Confirm';" & vbCrLf)
sb.Append("
alert(window.opener.document.getElementById('" &
Session("txtFunctionError") & "').value);" & vbCrLf)
sb.Append("
window.opener.document.Form1.submit();" & vbCrLf)
sb.Append(" window.opener.focus();" & vbCrLf)
sb.Append(" window.close();" & vbCrLf)

The first alert returns "ReadConflict" which is correct.
The second alert returns the value of "Confirm" which is correct.

The problem is during postback of the main window when I do a
Request.Form("txtFunctionError") the value it returns is
"ReadConflict", which is incorrect.
 
T

Timo

Alexey,

I found the problem and it is rather stupid but hey, it worked for
several years right?

txtFunctionError and several controls like it are basically hidden
text fields that I used to hold variables. They are hidden during
production use however, during testing they are visible so I can see
their values at any time. Since I wanted to see them during testing I
made them readonly. Well, appearently something doesn't like readonly
anymore. I disabled the readonly value and sure enough, it started
working again. I guess I will just have to live with having them
invisible.

Thanks for all your help.

Tim Frawley
 
A

Alexey Smirnov

Alexey,

The main problem is that txtFunctionError is a control that exists on
the main window, not the popup.  The popup is attempting to change the
value of the control on the main window and then closes itself.  I
tested the value of txtFunctionError.ClientID and it returns
"txtFunctionError".  I used a Session variable to hold the value of
txtFunctionError.ClientID and then write it to the javascript script
block I am appending.  I cannot reference the control on the main
window from the popup window using code behind (asp.net language).

Timo, I reread your original post and it sound like the problem is
different from the one I first thought. You said that
txtFunctionError.ClientID returns "txtFunctionError" and it's changed.
The problem is that it's changed on the client and to make it changed
in the Request.Form collection you do have to put it in a hidden
field.

Example:

add in the main window form

<asp:HiddenField ID="HiddenField1" runat="server" />

in the pop-up

document.getElementById("<%=HiddenField1.ClientID%>").value =
'Confirm'; // or Session(....)

then after the postback you should have your new value as

HiddenField1.Value
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top