Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Creating a popup via navigateurl in c#?

Posted on 2004-04-11
12
Medium Priority
?
4,344 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
ID: 10803840
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
ID: 10804629
<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:Volkan Vardar
ID: 10805383

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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 1

Author Comment

by:dbruyere
ID: 10809341
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
ID: 10811114
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:Volkan Vardar
ID: 10812146
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
 
LVL 1

Author Comment

by:dbruyere
ID: 10817264
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:
Volkan Vardar earned 2000 total points
ID: 10821931
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
ID: 10825154
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
ID: 10825429
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:Volkan Vardar
ID: 10830725
it works as u want in both pages :-)

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

Author Comment

by:dbruyere
ID: 10834714
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

FAQ pages provide a simple way for you to supply and for customers to find answers to the most common questions about your company. Here are six reasons why your company website should have a FAQ page
Although a lot of people devote their energy toward marketing for specific industries, there are some basic principles that can be applied to any sector imaginable. We’ll look at four steps to take and examine how those steps were put into action fo…
Any person in technology especially those working for big companies should at least know about the basics of web accessibility. Believe it or not there are even laws in place that require businesses to provide such means for the disabled and aging p…
The is a quite short video tutorial. In this video, I'm going to show you how to create self-host WordPress blog with free hosting service.
Suggested Courses

877 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