Monday, March 26, 2012

passing variable from Popup

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.
JJyes or I was using:
btn_browse.Attributes.Add("onclick", "java script:window.open('..etc
"Mark Rae" <mark@.markNOSPAMrae.com> wrote in message
news:uJ5DjU0$GHA.3536@.TK2MSFTNGP03.phx.gbl...
> "JJ" <abc@.xyz.com> wrote in message
> news:eEdelQ0$GHA.4680@.TK2MSFTNGP04.phx.gbl...
>
> When you say 'popup', do you mean you're using showModalDialog...?
>
"JJ" <abc@.xyz.com> wrote in message
news:eEdelQ0$GHA.4680@.TK2MSFTNGP04.phx.gbl...

> 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...?
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
"JJ" wrote:

> 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 a
n
> image URL. To select the url , the user can click on a browse button to op
en
> 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 losin
g
> 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
>
>
Thanks Lokesh. But is there any way of doing this in ASP.net rather than
javascript?
"Lokesh Reddy" <Lokesh Reddy@.discussions.microsoft.com> wrote in message
news:662ECFA3-6669-4DC7-97CF-334B00111516@.microsoft.com...
> 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
> "JJ" wrote:
>
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
"JJ" <abc@.xyz.com> wrote in message
news:e0Vl2y0$GHA.1464@.TK2MSFTNGP02.phx.gbl...
> Thanks Lokesh. But is there any way of doing this in ASP.net rather than
> javascript?
> "Lokesh Reddy" <Lokesh Reddy@.discussions.microsoft.com> wrote in message
> news:662ECFA3-6669-4DC7-97CF-334B00111516@.microsoft.com...
>
"JJ" <abc@.xyz.com> wrote in message
news:e0Vl2y0$GHA.1464@.TK2MSFTNGP02.phx.gbl...

> 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.
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/C
ivic_photo.gif');
window.opener.document.forms(0).submit();self.close();</SCRIPT>
(forgive me but I'm not too familiar with javascript)
JJ
"Lokesh Reddy" <Lokesh Reddy@.discussions.microsoft.com> wrote in message
news:662ECFA3-6669-4DC7-97CF-334B00111516@.microsoft.com...
> 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
> "JJ" wrote:
>
Found the problem, the single quotes need to be double quotes. Sorry. Still
learning...
"JJ" <abc@.xyz.com> wrote in message
news:ObG8i62$GHA.2328@.TK2MSFTNGP02.phx.gbl...
> 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
>
>
>
>
>
> "Lokesh Reddy" <Lokesh Reddy@.discussions.microsoft.com> wrote in message
> news:662ECFA3-6669-4DC7-97CF-334B00111516@.microsoft.com...
>

0 comments:

Post a Comment