passing variable from Popup

J

JJ

Whats the best way to pass a variable from a popup to the current page
(without a postback on the current page).

I have a form on 'page1' with various text input boxes. One box contains an
image URL. To select the url , the user can click on a browse button to open
a url chooser pop up ('page2'). I want the url that is selected in 'page2'
to be posted back to 'page1' and displayed in the input box, without losing
the values a user has already input in the other textboxes on page1.

I can use the 'previouspage' method, but I don't think this can work with
popups can it? I don't want the user to lose any of the other textboxes if
they have to browse to the url chooser page then return to the page1.


hopefully that all makes sense.

JJ
 
M

Mark Rae

Whats the best way to pass a variable from a popup to the current page
(without a postback on the current page).

When you say 'popup', do you mean you're using showModalDialog...?
 
J

JJ

yes or I was using:
btn_browse.Attributes.Add("onclick", "javascript:window.open('..etc
 
G

Guest

Write this code, on click event on button leads to close the popup.

/* Start from here*/
String sURL =’’ // selected url
string strScript = "<SCRIPT>window.opener.SendBackURLTOMainPage(‘ + sURL
+’); window.opener.document.forms(0).submit();
self.close();</SCRIPT>";

Page.RegisterClientScriptBlock("ClosePopup", strScript);
/* Ends here*/


Declare the this javascript function SendBackURLTOMainPage(val) in the main
page (aspx)
hdnURL is the hidden variable which store the selected URL from the popup
page.

function SendBackURLTOMainPage (val)
{
document.getElementById("hdnURL").innerText = val;
}

all the best,
Lokesh
 
J

JJ

Thanks Lokesh. But is there any way of doing this in ASP.net rather than
javascript?
 
J

JJ

Also,

If I wanted to pass the variable into different textboxes, (depending on
which 'browse' button was clicked) is there a way of doing this?

JJ
 
M

Mark Rae

Thanks Lokesh. But is there any way of doing this in ASP.net rather than
javascript?

No. ASP.NET is server-side, and can't obviously open windows client-side -
you need JavaScript for that.
 
J

JJ

Ok I've been trying to do this but without success:
I have a button on my urlChooser page:
protected void Button1_OnClick(object sender, System.EventArgs e)

{

String sURL = this.ImageURL_txtbox.Text; // selected url

string strScript = "<SCRIPT>window.opener.SendBackURLTOMainPage('" + sURL +
"'); window.opener.document.forms(0).submit();self.close();</SCRIPT>";

Page.ClientScript.RegisterClientScriptBlock(this.GetType(),"ClosePopup",
strScript);

}

and the javascript function in my main page is:

<script type="text/javascript">

function SendBackURLTOMainPage (val)

{

document.getElementById('TextBox1').value=val;

}

</script>



However, the urlChooser page comes up with an error when I click the button,
and the urlChooser window doesn't close. The error says there's an invald
character in this line:

<SCRIPT>window.opener.SendBackURLTOMainPage('/WebSite1/Uploads/XPS1/admin2/Civic_photo.gif');
window.opener.document.forms(0).submit();self.close();</SCRIPT>


(forgive me but I'm not too familiar with javascript)



JJ
 
J

JJ

Found the problem, the single quotes need to be double quotes. Sorry. Still
learning....
 

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

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,077
Latest member
SangMoor21

Latest Threads

Top