Solved

Creating a popup via navigateurl in c#?

Posted on 2004-04-11
12
4,242 Views
Last Modified: 2008-01-09
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
0
Comment
Question by:dbruyere
12 Comments
 

Expert Comment

by:Leifons
Comment Utility
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
 
LVL 35

Expert Comment

by:YZlat
Comment Utility
<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
 
LVL 6

Expert Comment

by:vardium
Comment Utility

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
 
LVL 1

Author Comment

by:dbruyere
Comment Utility
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
 
LVL 1

Expert Comment

by:Darix
Comment Utility
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
 
LVL 6

Expert Comment

by:vardium
Comment Utility
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
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
LVL 1

Author Comment

by:dbruyere
Comment Utility
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
 
LVL 6

Accepted Solution

by:
vardium earned 500 total points
Comment Utility
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
 
LVL 1

Author Comment

by:dbruyere
Comment Utility
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
 
LVL 1

Author Comment

by:dbruyere
Comment Utility
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
 
LVL 6

Expert Comment

by:vardium
Comment Utility
it works as u want in both pages :-)

i think u achieved the problem in live page.
0
 
LVL 1

Author Comment

by:dbruyere
Comment Utility
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

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Both Easy and Powerful How easy is PHP? http://lmgtfy.com?q=how+easy+is+php (http://lmgtfy.com?q=how+easy+is+php)  Very easy.  It has been described as "a programming language even my grandmother can use." How powerful is PHP?  http://en.wikiped…
Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
This tutorial demonstrates how to identify and create boundary or building outlines in Google Maps. In this example, I outline the boundaries of an enclosed skatepark within a community park.  Login to your Google Account, then  Google for "Google M…
The viewer will learn how to dynamically set the form action using jQuery.

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now