"John Straumann" <> wrote in
news:6B4853E2-2EA9-483C-B0B5-:
> Hi all:
>
> I have a button on a web form that calls a method in the code-behind
> file,
>
> OnClick="cmdButton_Click"
>
> and I am wondering if it is possible to close the web form from the
> code-behind? Or would I have to use client-side script to call the
> code-behind method, and then close the form from the client?
>
> Can anyone make a suggestion and/or point me at an info source?
You cannot close directly from CodeBehind, but you can do something like
this (watch word wrap):
string close;
close = "<script language=\"javascript\">windows.Close();</script>";
LiteralControl lit = new LiteralControl(close);
ContainerControl.Controls.Add(lit);
NOTE: ContainerControl here is something like a panel or other container
that you can anchor code into.
An even better option is outputting client script, but I felt I was more
likely to have to test the code if I did that. The end result is you are
injecting javaScript to close the page.
--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA
Twitter: @gbworld
Blog:
http://gregorybeamer.spaces.live.com
*******************************************
| Think outside the box! |
*******************************************