Solved

Creating a popup via navigateurl in c#?

Posted on 2004-04-11
12
4,273 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
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

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…
"In order to have an organized way for empathy mapping, we rely on a psychological model and trying to model it in a simple way, so we will split the board to three section for each persona and a scenario and try to see what those personas would Do,…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

860 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