Web Form

Discussion in 'ASP .Net' started by Craig Pearson, Jul 23, 2003.

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

    craig
     
    Craig Pearson, Jul 23, 2003
    #1
    1. Advertising

  2. 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" <> wrote in message
    news:...
    > 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" <> wrote in message
    > news:%...
    > > How can I close a web form from code-behind code, insteal of client

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

    >
    >
     
    Craig Pearson, Jul 23, 2003
    #2
    1. Advertising

  3. 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" <> wrote in message
    news:...
    > 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" <> wrote in message
    > news:...
    > > 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" <> wrote in message
    > > news:%...
    > > > How can I close a web form from code-behind code, insteal of client

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

    > >
    > >

    >
    >
     
    Kevin Spencer, Jul 23, 2003
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Mart Rogers

    passing arguments from web-form to win-form

    Mart Rogers, Jul 8, 2003, in forum: ASP .Net
    Replies:
    3
    Views:
    594
    Natty Gur
    Jul 9, 2003
  2. Li Zhang
    Replies:
    4
    Views:
    6,087
    softip
    Feb 27, 2009
  3. Replies:
    5
    Views:
    778
    Steve C. Orr [MCSD, MVP, CSM, ASP Insider]
    Jun 12, 2007
  4. Rob R. Ainscough
    Replies:
    3
    Views:
    332
    Rob R. Ainscough
    Jun 14, 2005
  5. rob c
    Replies:
    4
    Views:
    335
    McKirahan
    Dec 30, 2005
Loading...

Share This Page