RegisterClientScriptBlock: What am I doing wrong

A

aaa

I am trying to activate the following code on the click event of a popup
window.
If I comment out the lines where I assign the values to the hidden fields
the Parent page submits otherwise it does nothing. I don't get it.
I have used this code before. Any help is appreciated.

string s="<script>";
s += "window.opener.Form1.hiddenID.value = " + 6 + ";";
s += "window.opener.Form1.hiddenFlag.value = \"" + 1 + "\";";
s += "window.opener.Form1.submit();";
s += "window.close();";
s += "</script>";
this.RegisterClientScriptBlock("addPopup",s);
 
B

billmiami2

Obviously you have a problem with those two lines. The code is
stopping before you get to the submit and close.

Are those two quotation marks in row in the second line? I can't
tell.

I always use

self.opener.document.getElementById('mycontrolname').value

Instead of referencing Form1.controlname in the calling window. This
helps ensure that the script will work with multiple browsers.

Bill E.
Hollywood, FL
 
A

aaa

Maybe I spoke too soon. It now does the submit but doesn't pass back
anything. It has something to do with 'document' in the DOM.

How is that different than say Form1 or forms[0], which by the way will not
submit the form.
 
B

billmiami2

Immediately after setting the controls and before submitting, check to
see that the values are actually being written to the controls in the
calling window as in

alert(self.opener.document.getElementById('mycontrolname').value);

Also, how and where are you picking up these values in the calling page
in your code?

Bill
 
B

billmiami2

Can you tell us why you're using escape characters in the second line

s += "window.opener.Form1.hiddenFlag.value = \"" + 1 + "\";";

Is hiddenFlag a checkbox? If so, why can't you simply use

s += "window.opener.Form1.hiddenFlag.checked = 1;";

or

s += "self.opener.document.getElementById('hiddenFlag').checked = 1;";

Bill E.
 

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

Members online

No members online now.

Forum statistics

Threads
473,777
Messages
2,569,604
Members
45,228
Latest member
MikeMichal

Latest Threads

Top