Asp.net Forum

Ask Question   UnAnswered
Home » Forum » Asp.net       RSS Feeds

pop up window

  Asked By: Daisy    Date: Jan 18    Category: Asp.net    Views: 1160

Can i make a pop up window without using javascript
but using the language in the code behind it self (ie ia m using C#)?
If possible can give me some example?



2 Answers Found

Answer #1    Answered By: Rene Sullivan     Answered On: Jan 18

You can "Register" the Javascript FROM your code  behind file,
or you can "Response.Write" it TO client side explicitly.

Answer #2    Answered By: Milton Robinson     Answered On: Jan 18

No, you have to use javascript.

Think about what it is you are doing.

The user opens his browser on the client machine, sends a request to the server, which, using C# does it's bit on the server which is miles away from the client machine and then sends a load of html/script/embedded back to the browser running on the client machine.

Remember that when you open a pop  up what you are actually doing is opening a new browser, and that browser software is on the client ( and miles away from the server and your C#).
So the code  to open a new browser must execute on that client.
So you have to send it that code to execute.
We send it javacsript.
We could send it VBScript.
These scripts we can send it because we can execute them, courtesy of the browser.

We could send the client an exe ... but how could we execute it ??

There is another way - but it involves Windows Forms - and I'm not going to get into it here unless you request it - briefly ::

We need to send the client machine executable code - we do it using the scripting languages because we can - but if we could send it an executable - we might like to.
Actually we can.
We could send it a java applet.
We could send it an ActiveX control.
Or we could send it a C# embedded control.
All can do things - they can open up a different type of window, a windows window  or more recently a windows form.
They could actually be told to open up a new browser window.
They could be told to open up a Word document.
Or they could be told to completely erase your hard disk.
This latter point is why these things must have some sort of security - to stop abuse.
You've heard of java security.
And that ActiveX has no security : as soon as you install them you trust the cert. that comes with them.
.NET embedded controls have a security model that is better than java.
By default you cannot get one of these things to access anything on the client machine without EXPRESS permissions - and that includes accessing the software to open a new browser window.

So really the anwer is no - use javascript.
When you know about server controls it is quite simple to write some code and make a server control that outputs the required javascript .... you can then use a control like this in your everyday C#, much like a label, textbox or hyperlink and it would then "appear" that you are popping a new window using C#.
(the best way would be to extend the hyperlink to include an attribute that outputs the required javascript ... call it hypernewlink and you could use it like <yourcontrols:hypernewlink id="hnl_1" Url="http://www.msn.com">My Link To MSN</yourcontrols:hypernewlink>)

I haven't done it (yet) else I'd give  to it to you - I am surprised a control like this isn't available from just about anywhere.

In fact .... I might just make one and post it here.

The easier alternative is just to use a normal hyperlink as so

<asp:HyperLink id=HyperLink1 runat="server" NavigateUrl="http://www.msn.com" Target="_blank">HyperLink</asp:HyperLink>
Or from code
protected System.Web.UI.WebControls.HyperLink HyperLink1;
HyperLink1.NavigateUrl = "http://www.msn.com";
HyperLink1.Target = "_blank";

but then you cannot stipulate browser preferences.

Didn't find what you were looking for? Find more on pop up window Or get search suggestion and latest updates.