Creating a popup via navigateurl in c#?

I need to have the following link create a popup. I don't know how to do it. Please help.

LargerView.NavigateUrl = String.Format("largeview.aspx?ProductID={0}", ProductID);

largeview.aspx just has an image that gets it's file on page load. I need this to be the popup.

Derek
LVL 1
dbruyereAsked:
Who is Participating?
 
Volkan VardarConnect With a Mentor Software Team LeaderCommented:
if you want a popup then use this one

LargerView.NavigateUrl = String.Format("javascript:window.open('largeview.aspx?ProductID={0}','LargeView','width=500,height=400');void(0);", ProductID);
0
 
LeifonsCommented:
Hi,

Either write it in the .aspx page HTML section, or write at .cs file and register them. The easiest way of writing the script is to write it in the Head section, see below:
----------------------------------------
<html>
<head>
  <title>PopUp LargeView</title>
  <script language="javascript">
    function popup_largeview(prodID)
    {
      var myWin = null;
      myWin = window.open('largeview.aspx?ProductID=' + prodID, 'anycontent', 'width=500,height=400');
    }
  </script>
</head>
<body>
  <form name="Form1" method="post" action="WebForm1.aspx" id="Form1">
    <input type="button" onClick="popup_largeview(12)" value="Open larger view of image">
  </form>
</body>
</html>
----------------------------------------

The other way (two methods available) is to register a script in the .NET environment. They are RegisterStartupScript and RegisterClientScriptBlock.

Here's an example of the RegisterStartupScript method that you can use:
This method takes two parameters: RegisterStartupScript (string Key, string script).

Key is the unique key that identifies a script block and script is the content of the script that will be sent to the client. This method will embed the script just before the closing tag of the page object's <form runat="server" > element.

----------------------------------------
private void Page_Load(object sender, System.EventArgs e)
{
  if (!IsPostBack)
  {
    string PopUpWinURL = String.Format("largeview.aspx?ProductID={0}", ProductID);
    String scriptString = "<script language=JavaScript> " + Environment.NewLine;
    scriptString += "window.open('" + PopUpWinURL + "','mywindow','width=400,height=350')";
    scriptString += "</script>";
    if(!this.IsStartupScriptRegistered("LargerView"))
      this.RegisterStartupScript("LargerView", scriptString);
  }
}
----------------------------------------

Regards,
Leif
0
 
YZlatCommented:
<script language="javascript">
<!--
function new_window(url) {
               var iWidth, iHeight
               iWidth = screen.width/2;
               iHeight = screen.height/2;
               //alert(iWidth);
               link = window.open(url,"myWindow","toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=1,width=800,height=600,left=0,top=0");
          }
//-->
</script>


<asp:HyperLink id="LargerView" runat="server" Text=' ' Target=_blank NavigateUrl='<%# "largeview.aspx?ProductID={0}", ProductID %>'>Text
</asp:HyperLink>


Or

LargerView.NavigateUrl = String.Format("largeview.aspx?ProductID={0}", ProductID);
LargerView.Target="_blank"
0
Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

 
Volkan VardarSoftware Team LeaderCommented:

LargerView.NavigateUrl = String.Format("javascript:window.open('largeview.aspx?ProductID={0}','','toolbar=no,status=no,menubar=no,fullscreen=no,resizable=yes,scrollbars=yes,valign=center');void(0);", ProductID);

0
 
dbruyereAuthor Commented:
I have tried the code posted by vardium. It did a strange thing. It had a full new window open and then from that, sprung the popup that I wanted. I forgot to mention that I am using frames. Not sure if that would effect this one way or the other.

I also tried this bit from YZlat, and it just has a normal window opening (toolbars and all). I don't want all the toolbar stuff on there.

<script language="javascript">
<!--
function new_window(url) {
               var iWidth, iHeight
               iWidth = screen.width/2;
               iHeight = screen.height/2;
               //alert(iWidth);
               link = window.open(url,"myWindow","toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=1,width=800,height=600,left=0,top=0");
          }
//-->
</script>


<asp:HyperLink id="LargerView" runat="server" Text=' ' Target=_blank NavigateUrl='<%# "largeview.aspx?ProductID={0}", ProductID %>'>Text
</asp:HyperLink>


I also tried the first way from Leifons. The popup happened just fine, but it had an error that said the productID cannot be null. The second method posted from Leifons was beyond my understanding.
0
 
DarixCommented:
try to write:  

LargerView.NavigateUrl='javascript:window.open("http://www.google.com","myWindow","toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=1,width=800,height=600,left=0,top=0");'
0
 
Volkan VardarSoftware Team LeaderCommented:
if you still have

LargerView.Target="_blank"

it can cause this to happen. You should remove it. or you can try

LargerView.Target="_self"
0
 
dbruyereAuthor Commented:
So, the only one that I could get to do a standard popup is the first suggestion from Leifons. The problem is that the popup has an error. I think it' s becuase the productID variable is in the codebehind and html page cannot see it. Is there a way to get the same variable from the ocde behind into the html page? The variable (productID) is passed in the url from the product list page. If you need more information, please ask.

Thanks for all the suggestions.
0
 
dbruyereAuthor Commented:
vardium

I had trying that one and it is the one that had second full window open and from that window comes a popup with the image I want. I just realized that I had the target set to _blank which was causing the problem. Sorry for my ignorance. I am accepting your answer.
0
 
dbruyereAuthor Commented:
vardium

Right after I accepted your answer, I pushed the new page up to the live server and it didn't work the same. I had to set ithe target back to _blank. Which is now just poping up a full browser window. The strange thing is that on my dev box (which is my laptop running windows server 2003), I worked perfectly with the target set to _self  or _parent. If you have a moment here are the two IPs to view what's happening. Just navigate to "BOTTOMS" and click on the lagerview link.

Live:  www.moggjeans.com  (set to _blank)
dev:  http://63.196.244.194/paypalcommerce (a bit slow, it's on standard DSL on a wireless laptop). (set to _parent)

Derek
0
 
Volkan VardarSoftware Team LeaderCommented:
it works as u want in both pages :-)

i think u achieved the problem in live page.
0
 
dbruyereAuthor Commented:
I did acheive it. Thanks for all the help. Apparently my upload wasn't copying all the files (the bin folder) to the server. Fixed it and all is well.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.