473,473 Members | 1,933 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Web Form

How can I close a web form from code-behind code, insteal of client script
i.e javascript:window.close();

craig
Nov 17 '05 #1
2 4193
Hi Kevin

I have a server side button which needs to execute some code on the server,
then close the browser. Are you suggesting in the Page_Load, or prehaps the
button event (button_OnClick) I incorporate something like:

private void Page_Load(object sender, EventHandler e) {
if(IsPostback) {
// do server stuff, like clean out the session
// Session["var']=null;

Page.RegisterStartupScriptBlock("startup", "<script> window.close();
</script>");
}
}

I was attempting to do some sort of client script callback, whereby the
server script could call some client script, that way I could keep the
window.close() script 'pre-rendered' on the client. If you have a sample, I
would greatly appreciate it.

Craig


"Kevin Spencer" <ke***@takempis.com> wrote in message
news:up**************@tk2msftngp13.phx.gbl...
You can't. You're not trying to close a WebForm; you're trying to close the browser. The browser is on the client. All ASP.Net sends to the browser is
an HTTP response with HTML in it. You need to add a Startup JavaScript to
the page during PostBack that closes the browser window on the client side.
--
HTH,

Kevin Spencer
Microsoft MVP
.Net Developer
http://www.takempis.com
Big things are made up of
lots of little things.

"Craig Pearson" <pe******@un.org> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
How can I close a web form from code-behind code, insteal of client script i.e javascript:window.close();

craig


Nov 17 '05 #2
What you just posted is fine. Since, as you say, you want to execute some
server-side processing, you would then add the script to the page so that it
closes when loaded into the browser.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
http://www.takempis.com
Big things are made up of
lots of little things.

"Craig Pearson" <pe******@un.org> wrote in message
news:eF**************@TK2MSFTNGP10.phx.gbl...
Hi Kevin

I have a server side button which needs to execute some code on the server, then close the browser. Are you suggesting in the Page_Load, or prehaps the button event (button_OnClick) I incorporate something like:

private void Page_Load(object sender, EventHandler e) {
if(IsPostback) {
// do server stuff, like clean out the session
// Session["var']=null;

Page.RegisterStartupScriptBlock("startup", "<script> window.close();
</script>");
}
}

I was attempting to do some sort of client script callback, whereby the
server script could call some client script, that way I could keep the
window.close() script 'pre-rendered' on the client. If you have a sample, I would greatly appreciate it.

Craig


"Kevin Spencer" <ke***@takempis.com> wrote in message
news:up**************@tk2msftngp13.phx.gbl...
You can't. You're not trying to close a WebForm; you're trying to close

the
browser. The browser is on the client. All ASP.Net sends to the browser is
an HTTP response with HTML in it. You need to add a Startup JavaScript to the page during PostBack that closes the browser window on the client

side.

--
HTH,

Kevin Spencer
Microsoft MVP
.Net Developer
http://www.takempis.com
Big things are made up of
lots of little things.

"Craig Pearson" <pe******@un.org> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
How can I close a web form from code-behind code, insteal of client

script i.e javascript:window.close();

craig



Nov 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: John | last post by:
Dear all, It been more than 3 days I am trying to debug this program, I interpret it using activePerl and it is giving (perl -wc code_process.pl) no error syntax but when I put it online, change...
5
by: Richard Cornford | last post by:
I am interested in hearing opinions on the semantic meaning of FORM (elements) in HTML. I have to start of apologising because this question arose in a context that is not applicable to the...
4
by: Targa | last post by:
Trying to total some price fields in a form but doesnt work when all the referenced form fields dont exisit. This is for an invoice - pulled prom a database and the form doesnt always contain the...
25
by: Lyn | last post by:
Hi, I am working on a genealogy form. The only table (so far) lists everybody in the family, one record per person. Each record has an autonum ID. The parent form (frmMainForm) displays the...
19
by: Raposa Velha | last post by:
Hello to all! Does any of you want to comment the approach I implement for instantiating a form? A description and an example follow. Cheers, RV jmclopesAThotmail.com replace the AT with the...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.