ASP.Net - Opening new windows using C#

  • Thread starter Thread starter Jeremy Ames
  • Start date Start date
J

Jeremy Ames

Is there a way, without using javascript, to open a new browser window at
set the window attributes? I want to set the size, turn off the status bar,
address bar, menu bar, and etc. Can someone please help?
 
Hi jeremy,

What you want is not possible, the concept of "windows" exist only in the
client side of the application, in this side is javascript what you use.

Now, the question is why not use javascript?

Cheers,
 
I would prefer to keep all of the code on the server side. I have found that
I can do so much more with the code on the server side ( more secure) than
on the client. I was wanting to test some user input against a database, and
if any problems were encountered, open a window for the specific type of
error.

Perhaps you can help there. I have this code being ran on the onclick event
of a button. Is it possible to run the server script for that control and
then run the client script?

"Ignacio Machin ( .NET/ C# MVP )" <ignacio.machin AT dot.state.fl.us> wrote
in message Hi jeremy,

What you want is not possible, the concept of "windows" exist only in the
client side of the application, in this side is javascript what you use.

Now, the question is why not use javascript?

Cheers,
 
HI Jeremy,

As I said the window is a client side concept and is only from the client
side that you can create them, now in your escenario its possible to
generate the client code from the code behind, like this:

in the aspx file:
<Script>
var openwindow="no";
var windowURL = "";

function CheckIFNeededOpenWindow()
{
if ( openwindow == "yes" )
window.open( windowURL, .... )
}
</script>
<body onLoad = CheckIFNeededOpenWindow(); >


now in the .cs code :
void button_onclick(sender o , eventargs e)
{
//do the validation, if error open the new window
if ( error )
{
Literal lit = new Literal();
lit.Text= "<script> openwindow=\"yes\"; windowURL=\"" + URL_TO_OPEN +
"\";</script>" ;
Controls.Add( lit);
}
}


With the above code you can solve your problem, if you have any other doubt
just post back,


Cheers,
 
Wouldn't this script run every time the page is reprocessed?

"Ignacio Machin ( .NET/ C# MVP )" <ignacio.machin AT dot.state.fl.us> wrote
in message HI Jeremy,

As I said the window is a client side concept and is only from the client
side that you can create them, now in your escenario its possible to
generate the client code from the code behind, like this:

in the aspx file:
<Script>
var openwindow="no";
var windowURL = "";

function CheckIFNeededOpenWindow()
{
if ( openwindow == "yes" )
window.open( windowURL, .... )
}
</script>
<body onLoad = CheckIFNeededOpenWindow(); >


now in the .cs code :
void button_onclick(sender o , eventargs e)
{
//do the validation, if error open the new window
if ( error )
{
Literal lit = new Literal();
lit.Text= "<script> openwindow=\"yes\"; windowURL=\"" + URL_TO_OPEN +
"\";</script>" ;
Controls.Add( lit);
}
}


With the above code you can solve your problem, if you have any other doubt
just post back,


Cheers,
 
Back
Top