Web Form

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Craig Pearson

    #1

    Web Form

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

    craig


  • Craig Pearson

    #2
    Re: Web Form

    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(objec t sender, EventHandler e) {
    if(IsPostback) {
    // do server stuff, like clean out the session
    // Session["var']=null;

    Page.RegisterSt artupScriptBloc k("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" <kevin@takempis .com> wrote in message
    news:upn4DuSUDH A.3712@tk2msftn gp13.phx.gbl...[color=blue]
    > You can't. You're not trying to close a WebForm; you're trying to close[/color]
    the[color=blue]
    > 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[/color]
    side.[color=blue]
    >
    > --
    > HTH,
    >
    > Kevin Spencer
    > Microsoft MVP
    > .Net Developer
    > http://www.takempis.com
    > Big things are made up of
    > lots of little things.
    >
    > "Craig Pearson" <pearson4@un.or g> wrote in message
    > news:%23D6lTYSU DHA.2188@TK2MSF TNGP10.phx.gbl. ..[color=green]
    > > How can I close a web form from code-behind code, insteal of client[/color][/color]
    script[color=blue][color=green]
    > > i.e javascript:wind ow.close();
    > >
    > > craig
    > >
    > >[/color]
    >
    >[/color]


    Comment

    • Kevin Spencer

      #3
      Re: Web Form

      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
      All hotels in Benidorm. The best selection of Benidorm hotels with reviews and maps. Book in advance and save.

      Big things are made up of
      lots of little things.

      "Craig Pearson" <pearson4@un.or g> wrote in message
      news:eFdEiKTUDH A.2036@TK2MSFTN GP10.phx.gbl...[color=blue]
      > Hi Kevin
      >
      > I have a server side button which needs to execute some code on the[/color]
      server,[color=blue]
      > then close the browser. Are you suggesting in the Page_Load, or prehaps[/color]
      the[color=blue]
      > button event (button_OnClick ) I incorporate something like:
      >
      > private void Page_Load(objec t sender, EventHandler e) {
      > if(IsPostback) {
      > // do server stuff, like clean out the session
      > // Session["var']=null;
      >
      > Page.RegisterSt artupScriptBloc k("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,[/color]
      I[color=blue]
      > would greatly appreciate it.
      >
      > Craig
      >
      >
      >
      >
      > "Kevin Spencer" <kevin@takempis .com> wrote in message
      > news:upn4DuSUDH A.3712@tk2msftn gp13.phx.gbl...[color=green]
      > > You can't. You're not trying to close a WebForm; you're trying to close[/color]
      > the[color=green]
      > > browser. The browser is on the client. All ASP.Net sends to the browser[/color][/color]
      is[color=blue][color=green]
      > > an HTTP response with HTML in it. You need to add a Startup JavaScript[/color][/color]
      to[color=blue][color=green]
      > > the page during PostBack that closes the browser window on the client[/color]
      > side.[color=green]
      > >
      > > --
      > > HTH,
      > >
      > > Kevin Spencer
      > > Microsoft MVP
      > > .Net Developer
      > > http://www.takempis.com
      > > Big things are made up of
      > > lots of little things.
      > >
      > > "Craig Pearson" <pearson4@un.or g> wrote in message
      > > news:%23D6lTYSU DHA.2188@TK2MSF TNGP10.phx.gbl. ..[color=darkred]
      > > > How can I close a web form from code-behind code, insteal of client[/color][/color]
      > script[color=green][color=darkred]
      > > > i.e javascript:wind ow.close();
      > > >
      > > > craig
      > > >
      > > >[/color]
      > >
      > >[/color]
      >
      >[/color]


      Comment

      Working...