Solved

Creating a popup via navigateurl in c#?

Posted on 2004-04-11
12
4,284 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

 
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 500 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

Suggested Solutions

Title # Comments Views Activity
Create animated movies for web page 18 120
how can i make amazon approved mobile url 4 37
need help with share buttons 11 69
.CSS HTML Help 3 24
I've been asked to discuss some of the UX activities that I'm using with my team. Here I will share some details about how we approach UX projects.
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
This tutorial walks through the best practices in adding a local business to Google Maps including how to properly search for duplicates, marker placement, and inputing business details. Login to your Google Account, then search for "Google Mapmaker…
The viewer will learn how to count occurrences of each item in an array.

749 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