Wrox Programmer Forums
|
ASP.NET 1.1 As of 10/6/2005, this forum is locked as part of the reorganization described here: http://p2p.wrox.com/topic.asp?TOPIC_ID=35394. No posts have been deleted. Open ongoing discussions from the last week have been moved to either ASP.NET 1.0 and 1.1 Beginners http://p2p.wrox.com/asp-net-1-0-1-1-basics-60/ or ASP.NET 1.0 and 1.1 Professional. http://p2p.wrox.com/forum.asp?FORUM_ID=50. See my sticky post inside for more.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.1 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 26th, 2004, 04:02 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
Default Using Two Forms

Hello,

I have an ASP.NET application, where in one form I open another form with window.open. Regardless of what the form does, specifically to javascript in the opened form, I want to redirect the original form (I tried with window.opener.location = '<value>';) and then close the opened form (with window.close();).

That should work fine; however, I try to call that function that handles that in the ASP.NET code by doing a (in the button click event):

Response.Write("<script>CloseForm();</script>")

That function handles the javascript events described above. That isn't working, because it is putting it above the html tag, and I think that is what's giving me an error.

How in ASP.NET would I execute a javascript function to close the form and redirect the original form to another location?

Thanks,

Brian
__________________
Brian
 
Old July 27th, 2004, 06:26 AM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

You should avoid Response.Write in ASP.NET at all costs.

You want "Page.RegisterStartupScript".

http://msdn.microsoft.com/library/en...criptTopic.asp

This dumps literal string you provide onto the page "just before the closing tag of the Page object's <form runat= server> element".

Another function that may be of use to you is RegisterClientScriptBlock. This function does the same thing, but puts the script block at the beginning of the page. I use this for dynamic styles or in cases where I need a user control to dump javascript or styles to the page. One of the key points of these functions is that you can pass a key for the script block. If another call is made with the same key, the block is ignored. This is very useful for when you have a user control with generic javascript. Multiple instances of the control call this method but only the first will actually get written out, thus reducing the overall weight of the page. You just have to make sure you write "generic" user control javascript.
 
Old July 27th, 2004, 08:21 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
Default

Hey,

Thanks, that worked. What was throwing me off was that there was no intellisense for the method... I hate hidden functions.

Thanks again, that worked like a charm.

Brian
 
Old July 27th, 2004, 09:15 AM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

Yeah, the intellisense that shows the functions is missing, but once you have it the function signature shows up. I have wondered if there is some reason it's missing.
 
Old July 27th, 2004, 10:49 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 839
Thanks: 0
Thanked 1 Time in 1 Post
Default

Quote:
quote:Originally posted by planoie
 Yeah, the intellisense that shows the functions is missing, but once you have it the function signature shows up. I have wondered if there is some reason it's missing.
You probably have the "Hide advanced members" option set, which I believe is set by default.

Go to Tools->Options->Text Editor->Basic->General and make sure the "Hide advanced members" checkbox is NOT checked in the Statement Completion section.


Jeff Mason
Custom Apps, Inc.
www.custom-apps.com
 
Old July 27th, 2004, 11:57 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
Default

Jeff,

That did it.

Thanks.
 
Old July 27th, 2004, 01:30 PM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

WOW!!!! Thanks Jeff! How the heck did I ever miss that! And to think, I thought I had a clue.
 
Old July 27th, 2004, 01:56 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
Default

Hey,

One more thing about the two forms thing. Whenever I load the second form, it loads the form, then switches the focus back to the first one. Is there any way that I can give the focus back to the second? Maybe through a field focus (ie. document.getElementById('TextBox1').focus();)?

I'm using window.open to load the second form.

Thanks,

Brian
 
Old July 27th, 2004, 02:04 PM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

In the javascript you are writing to the page, do something like this:

var objWin = window.open(....);
objWin.focus();

However... it sounds like you are using smart navigation on the opening page so this might be what's kicking the focus back, and the above suggestion may still not work.
 
Old July 27th, 2004, 02:20 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
Default

Hey,

I'll try it. I'm not committed to the smartNavigation, so....

Brian





Similar Threads
Thread Thread Starter Forum Replies Last Post
Forms ghall202 Access VBA 5 February 13th, 2007 10:32 AM
Forms and Sub forms Mink Access 1 December 1st, 2004 08:38 AM
Opening forms from other forms Paulsh Access VBA 1 September 30th, 2004 06:54 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.