Popup window passes value to opener but not recognized

Popup window passes value to opener but not recognized

am 12.01.2008 00:02:12 von 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').va lue='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.

Re: Popup window passes value to opener but not recognized

am 12.01.2008 17:34:58 von lexa

On Jan 12, 12:02=A0am, Timo wrote:
> I created this application using ASP.NET 1.0 and it has worked great
> for several years. =A0I recently upgraded to 2.0 and now this isn't
> working:
>
> I have a popup window that indicates to the user a problem. =A0They have
> several choices, in all of them I change the value of items on the
> opener window like so:
>
> window.opener.document.getElementById('txtFunctionError').va lue=3D'Confirm=
';
> =A0 window.opener.document.Form1.submit();
> =A0 window.opener.focus();
> =A0 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. =A0The 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("<%=3DtxtFunctionError.ClientID%>")

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

Re: Popup window passes value to opener but not recognized

am 14.01.2008 19:56:50 von 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("" & vbCrLf)
ClientScript.RegisterClientScriptBlock(Me.GetType(),
"ClientScripts", sb.ToString)




> If txtFunctionError is the server control then you should change your
> script to
>
> getElementById("<%=txtFunctionError.ClientID%>")
>
> where ClientID returns the server control identifier generated byASP.NET.- Hide quoted text -
>
> - Show quoted text -

Re: Popup window passes value to opener but not recognized

am 14.01.2008 20:35:08 von lexa

On Jan 14, 7:56=A0pm, Timo wrote:
> Alexey,
>
> Thank you for your response. =A0I am registering a client script block
> for my javascript so the inline write <%=3D%> doesn't work for me. =A0Here=

> 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]

Re: Popup window passes value to opener but not recognized

am 15.01.2008 00:17:17 von 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.

Re: Popup window passes value to opener but not recognized

am 15.01.2008 00:48:22 von 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

Re: Popup window passes value to opener but not recognized

am 15.01.2008 00:48:37 von lexa

On Jan 15, 12:17=A0am, Timo wrote:
> Alexey,
>
> The main problem is that txtFunctionError is a control that exists on
> the main window, not the popup. =A0The popup is attempting to change the
> value of the control on the main window and then closes itself. =A0I
> tested the value of txtFunctionError.ClientID and it returns
> "txtFunctionError". =A0I used a Session variable to hold the value of
> txtFunctionError.ClientID and then write it to the javascript script
> block I am appending. =A0I 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



in the pop-up

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

then after the postback you should have your new value as

HiddenField1.Value