Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Controls > pop-up browser persist data back to parent page code-behind

Reply
Thread Tools

pop-up browser persist data back to parent page code-behind

 
 
David Thielen
Guest
Posts: n/a
 
      03-23-2006
Hi;

Here is what I want to do. On my main page there will be a button that says
"Get File" pressing that pops up a second browser window with a FileUpload
control in it. The user selects a file and then presses submit in this popup
window.

The file is uploaded, the pop-up browser goes away, the file is saved in the
class for the main window code behind, and the main page is redrawn to show
that the file has been uploaded.

Can I do this and if so - how?

--
thanks - dave
david_at_windward_dot_net
http://www.windwardreports.com

 
Reply With Quote
 
 
 
 
Steven Cheng[MSFT]
Guest
Posts: n/a
 
      03-23-2006
Hi Dave,

When we open a new browser window from one browser window/page, the
relation between them can be get through client-side script, server-side
page model have no sense of client windows. And for opener and child
window, we can use the "window.opener" script code to reference them.

So, for your scenario, I think you can consider registering a client-script
block after the upload page(sub page) have processed and saved the uploaded
file. The script will call a script function in the opener page and close
itself. e.g;

================
public partial class Upload_UploadDlg : System.Web.UI.Page
{
public const string SCRIPT = @"
<script language='javascript'>
window.opener.end_upload();

window.self.close();
</script>
";

protected void Page_Load(object sender, EventArgs e)
{

}
protected void btnUpload_Click(object sender, EventArgs e)
{
if (fu1.HasFile)
{
Session["upload_file_name"] = fu1.FileName;

lblMessage.Text = "file is uploaded at " +
DateTime.Now.ToLongTimeString();

Page.ClientScript.RegisterStartupScript(this.GetTy pe(),
"close_script", SCRIPT);
}
}
}
===========================


as you see, in the upload page, i stored the uploaded file's name in the
session for later use. Then, register the client script to call a script
function defined in opener page and close itself.

In the opener page, the clientscript is like below:

============
function end_upload()
{
document.getElementById("btnSubmit").click();
}
=============

it programmatically call a button's click method to submit the page. We can
then do some processing on the server and read the uploaded filename from
session.

BTW, if you do not need to do any server-side processing on the opener
page, just want to show the uploaded file's name. We can just let the
upload page's script pass the name to opener page through the script
function, that can avoid additional postback.

Hope this helps.


Regards,

Steven Cheng
Microsoft Online Community Support


==================================================

When responding to posts, please "Reply to Group" via your newsreader so
that others may

learn and benefit from your issue.

==================================================


This posting is provided "AS IS" with no warranties, and confers no rights.

 
Reply With Quote
 
 
 
 
David Thielen
Guest
Posts: n/a
 
      03-23-2006
Hello;

I am missing something here. I don't see how the file contents and filename
are getting back to the main page???

--
thanks - dave
david_at_windward_dot_net
http://www.windwardreports.com



"Steven Cheng[MSFT]" wrote:

> Hi Dave,
>
> When we open a new browser window from one browser window/page, the
> relation between them can be get through client-side script, server-side
> page model have no sense of client windows. And for opener and child
> window, we can use the "window.opener" script code to reference them.
>
> So, for your scenario, I think you can consider registering a client-script
> block after the upload page(sub page) have processed and saved the uploaded
> file. The script will call a script function in the opener page and close
> itself. e.g;
>
> ================
> public partial class Upload_UploadDlg : System.Web.UI.Page
> {
> public const string SCRIPT = @"
> <script language='javascript'>
> window.opener.end_upload();
>
> window.self.close();
> </script>
> ";
>
> protected void Page_Load(object sender, EventArgs e)
> {
>
> }
> protected void btnUpload_Click(object sender, EventArgs e)
> {
> if (fu1.HasFile)
> {
> Session["upload_file_name"] = fu1.FileName;
>
> lblMessage.Text = "file is uploaded at " +
> DateTime.Now.ToLongTimeString();
>
> Page.ClientScript.RegisterStartupScript(this.GetTy pe(),
> "close_script", SCRIPT);
> }
> }
> }
> ===========================
>
>
> as you see, in the upload page, i stored the uploaded file's name in the
> session for later use. Then, register the client script to call a script
> function defined in opener page and close itself.
>
> In the opener page, the clientscript is like below:
>
> ============
> function end_upload()
> {
> document.getElementById("btnSubmit").click();
> }
> =============
>
> it programmatically call a button's click method to submit the page. We can
> then do some processing on the server and read the uploaded filename from
> session.
>
> BTW, if you do not need to do any server-side processing on the opener
> page, just want to show the uploaded file's name. We can just let the
> upload page's script pass the name to opener page through the script
> function, that can avoid additional postback.
>
> Hope this helps.
>
>
> Regards,
>
> Steven Cheng
> Microsoft Online Community Support
>
>
> ==================================================
>
> When responding to posts, please "Reply to Group" via your newsreader so
> that others may
>
> learn and benefit from your issue.
>
> ==================================================
>
>
> This posting is provided "AS IS" with no warranties, and confers no rights.
>
>

 
Reply With Quote
 
Steven Cheng[MSFT]
Guest
Posts: n/a
 
      03-24-2006
Hi Dave,

I just store the uploaded files file name in a Session variable, thus
when the main page postback, the code can check that session variable to
get the filename. Also, if you want to access any other info about the
file, you can provide a path to the temp file on the server so that it can
access that files content.

Regards,

Steven Cheng
Microsoft Online Community Support


==================================================

When responding to posts, please "Reply to Group" via your newsreader so
that others may

learn and benefit from your issue.

==================================================


This posting is provided "AS IS" with no warranties, and confers no rights.


 
Reply With Quote
 
David Thielen
Guest
Posts: n/a
 
      03-24-2006
Hi;

Oh, I get it now. Temp file on the server. Any suggestions on how to do this
if I don't want a temp file on the server?

--
thanks - dave
david_at_windward_dot_net
http://www.windwardreports.com



"Steven Cheng[MSFT]" wrote:

> Hi Dave,
>
> I just store the uploaded file¡¯s file name in a Session variable, thus
> when the main page postback, the code can check that session variable to
> get the filename. Also, if you want to access any other info about the
> file, you can provide a path to the temp file on the server so that it can
> access that file¡¯s content.
>
> Regards,
>
> Steven Cheng
> Microsoft Online Community Support
>
>
> ==================================================
>
> When responding to posts, please "Reply to Group" via your newsreader so
> that others may
>
> learn and benefit from your issue.
>
> ==================================================
>
>
> This posting is provided "AS IS" with no warranties, and confers no rights.
>
>
>

 
Reply With Quote
 
Steven Cheng[MSFT]
Guest
Posts: n/a
 
      03-27-2006
Thanks for your reply Dave,

In addition to using temp file, you can also consider storeing the file
content in memory or session, however, both of these two will cause serious
consumsion of server machine's memory which is not recommended. Another
option is use temp database to store the file content(binary data). Anyway,
the file content must be cached on server-side so that it can be reused
between multiple postbacks. And we need to delete as soon as we've finished
using it so as not to produce redundant cost.

Regards,

Steven Cheng
Microsoft Online Community Support


==================================================

When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.

==================================================


This posting is provided "AS IS" with no warranties, and confers no rights.

 
Reply With Quote
 
David Thielen
Guest
Posts: n/a
 
      03-28-2006
Hi;

How can I attach the file contents to the session so my original page then
has it to access from it's code behind? This will be a rare event so we
should usually have zero instances of this and occasionally 1 file content
attached to a session so I'm not worried about memory use.

--
thanks - dave
david_at_windward_dot_net
http://www.windwardreports.com



"Steven Cheng[MSFT]" wrote:

> Thanks for your reply Dave,
>
> In addition to using temp file, you can also consider storeing the file
> content in memory or session, however, both of these two will cause serious
> consumsion of server machine's memory which is not recommended. Another
> option is use temp database to store the file content(binary data). Anyway,
> the file content must be cached on server-side so that it can be reused
> between multiple postbacks. And we need to delete as soon as we've finished
> using it so as not to produce redundant cost.
>
> Regards,
>
> Steven Cheng
> Microsoft Online Community Support
>
>
> ==================================================
>
> When responding to posts, please "Reply to Group" via your newsreader so
> that others may learn and benefit from your issue.
>
> ==================================================
>
>
> This posting is provided "AS IS" with no warranties, and confers no rights.
>
>

 
Reply With Quote
 
Steven Cheng[MSFT]
Guest
Posts: n/a
 
      03-29-2006
Thanks for the reply Dave,

As for the file content, if they're binary file, you can just read out the
binary content out of the stream and store into a byte[] array, then, we
can directly put the byte array into Session through

byte[] myfilebytes = xxxx;
......
Session["file_bytes"] = myfilebytes;

Regards,

Steven Cheng
Microsoft Online Community Support


==================================================

When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.

==================================================


This posting is provided "AS IS" with no warranties, and confers no rights.




 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
If a class Child inherits from Parent, how to implementChild.some_method if Parent.some_method() returns Parent instance ? metal Python 8 10-30-2009 10:31 AM
Page not found error when navigating from the child page back to the parent page Samy Java 0 02-04-2006 01:29 AM
Page load of the parent page called twice when a modal dialog is opened from a button click of the user control on the parent page Samy ASP .Net 2 08-15-2005 03:30 PM
Parent to child back to parent Adrian MacNair Javascript 2 05-26-2005 08:01 PM
Parent - Child back to parent javascript thingybob mark ASP .Net 1 03-10-2005 02:20 PM



Advertisments