Solved

Help opening webpage as popup using ASP.NET C#

Posted on 2008-10-25
19
903 Views
Last Modified: 2010-04-21
I am dynamically creating this link... Right now, it opens a webpage, I need it to open a pop up window.

It needs to be in C#
strInfoHTML.Append("<td><a href='Detail.aspx?ContainerNumber=" + myReader["ContainerNumber"].ToString() + "' target='_blank'><font size=1>" + myReader["ContainerNumber"].ToString() + "</font></a><td>");

Open in new window

0
Comment
Question by:michael1174
  • 10
  • 9
19 Comments
 
LVL 12

Expert Comment

by:techExtreme
ID: 22804246
Hello,
Its easy, let me explain:
You create a javascript function and include it in the script tag in your page as shown
<script language="javascript" >
function mypopup(myurl, mywindowtitle)
 {
   mywindow = window.open (myurl,
  mywindowtitle,"location=1,status=1,scrollbars=1,
  width=100,height=100");
  mywindow.moveTo(0,0);
 }  
</script>
Then you call it from your anchor tag as shown below:
strInfoHTML.Append("<td><a onclick="javascript: mypopup(\"Detail.aspx?ContainerNumber=" + myReader["ContainerNumber"].ToString()); ","mytitle");");

just make sure there are no mistakes in here regarding quotes as I just wrote it in notepad :)
Hope it helped
Enjoy Coding!
 
0
 
LVL 2

Author Comment

by:michael1174
ID: 22804318
Hi, I think I have the syntax correct, but this string should display a hyperlink, and it does not:

strInfoHTML.Append("<td><a onclick='javascript: mypopup('Detail.aspx?ContainerNumber=" + myReader["ContainerNumber"].ToString() + ",'mytitle');");

As you can see in my original code, I had myReader["ContainerNumber"].ToString() as the hyperlink.  Using your code, I get no hyperlinks.


0
 
LVL 12

Expert Comment

by:techExtreme
ID: 22804414
Ok try this one:
strInfoHTML.Append("
<a href="javascript:anchor_test()">clickForPopUp</a>
"<a href=\"javascript:anchor_test('"
+ "Detail.aspx?ContainerNumber=" +  myReader["ContainerNumber"].ToString()
+ "','" + myReader["ContainerNumber"].ToString() + "')>" + myReader["ContainerNumber"].ToString() + "</a>"
");
Let me show you what it should render, so that you can counter check or correct it as requied
<a href="javascript:mypopup('Detail.aspx?ContainerNumber=101','101')>101</a>
assuming your reader's tostring method returns 101 as the container number
Enjoy Coding!
0
 
LVL 2

Author Comment

by:michael1174
ID: 22804452
Hi, thanks for you help, but that looks like two links, right?  

Why would i need: <a href="javascript:anchor_test()">clickForPopUp</a>

I tried to get it to work, but had problems with the double quotes and couldn't get a valid line in code to be correct.

0
 
LVL 2

Author Comment

by:michael1174
ID: 22804492
Hi, I got the following line to be a valid line following this example : <a href="javascript:mypopup('Detail.aspx?ContainerNumber=101','101')>101</a>

This line of code is valid:
strInfoHTML.Append("<td><a href='javascript:mypopup('Detail.aspx?ContainerNumber=" + myReader["ContainerNumber"].ToString() + "','" + myReader["ContainerNumber"].ToString() + "')>" + myReader["ContainerNumber"].ToString() + "</a>");

but when I run my webpage, the properties of the link are blank, which launches no popup:

javascript:mypopup(
0
 
LVL 12

Expert Comment

by:techExtreme
ID: 22804503
Sorry, I forgot to remove the line, remove the portion in bold
strInfoHTML.Append("<a href="javascript:anchor_test()">clickForPopUp</a>
"<a href=\"javascript:anchor_test('"
+ "Detail.aspx?ContainerNumber=" +  myReader["ContainerNumber"].ToString()
+ "','" + myReader["ContainerNumber"].ToString() + "')>" + myReader["ContainerNumber"].ToString() + "</a>"
");
Also I assume you are coding in c#.net right?
0
 
LVL 12

Expert Comment

by:techExtreme
ID: 22804516
w.r.t. to your post regarding partial success, if you get something like <a href=javascript: mypopup('','')></a>   then the data from the reader is not coming properly , test it.
also do not use the function anchor_test which i by mistake put it there, use our function which is mypopup.
When you do 'view source' on your page, you should see a proper anchor tag and the links should work then.
0
 
LVL 2

Author Comment

by:michael1174
ID: 22804532
The properties of the link read "javascript:mypopup(", and my data read is working properly because it even display the name of the link properly and I stepped through it as well.
0
 
LVL 12

Expert Comment

by:techExtreme
ID: 22804617
can you post the source of the page as when you see it in browser?
I doubt that due to some reason it is not rendered completely.   I would like to see the rendered portion of the anchor tag especially i.e. <a>.....</a> everything between it as it is rendered.
0
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
LVL 2

Author Comment

by:michael1174
ID: 22804669
When I view the source, I do not see the rendered link, because I think, that string that I am building is being passed into a parameter in a user control.

Anyway, thanks for your help though... I'll get it eventually.
0
 
LVL 12

Expert Comment

by:techExtreme
ID: 22804751
I can try looking in the source if the page is available online. Else its ok. Its very simple hope you get it where exactly its wrong over there.
 
0
 
LVL 2

Author Comment

by:michael1174
ID: 22804764
No, its local development so far.  I did a search for mypopup when viewing the source from the brower and the only code I came across was the function itself, and not the link we are trying to create.
0
 
LVL 12

Expert Comment

by:techExtreme
ID: 22804784
Ok I hope you got the idea of what exact html markup you have to generate for opening that popup.
0
 
LVL 2

Author Comment

by:michael1174
ID: 22806983
when i click on the properties of the link in internet explorer, its telling me the following:

protocol: unknown protocol
type: not available
address: javascript: mypopup(
(URL)

Any ideas why? I'm using VS 2008, asp.net 3.5.

And that string I am building is being passed in as a parameter with this call using a control:

GoogleMapForASPNet1.GoogleMapObject.Points.Add(new GooglePoint(intCount.ToString(), dblLatitude, dblLongitude,"",strInfoHTML.ToString(),"",false));



0
 
LVL 12

Expert Comment

by:techExtreme
ID: 22807158
Ya that's because  it is not well formed html. You can do view source for the rendered page and select the html where this anchor tag renders and paste here and also  right before where you are passing the string to your user control, do a .ToString() and take its string and paste it too  , it'll be helpful in debugging.

Enjoy Coding!
0
 
LVL 2

Author Comment

by:michael1174
ID: 22807182
Ok, this is the string it built:

"<table><tr><a href='javascript:popitup('Detail.aspx?ContainerNumber=MLKU 543152-8');'><font size=1>MLKU 543152-8</font></a><td><tr><a href='javascript:popitup('Detail.aspx?ContainerNumber=MLKU 543335-1');'><font size=1>MLKU 543335-1</font></a><td><a href='javascript:popitup('Detail.aspx?ContainerNumber=MLKU 543336-7');'><font size=1>MLKU 543336-7</font></a><td><tr><a href='javascript:popitup('Detail.aspx?ContainerNumber=MLKU 543338-8');'><font size=1>MLKU 543338-8</font></a><td><a href='javascript:popitup('Detail.aspx?ContainerNumber=MLKU 543340-7');'><font size=1>MLKU 543340-7</font></a><td><tr><a href='javascript:popitup('Detail.aspx?ContainerNumber=MLKU 543344-9');'><font size=1>MLKU 543344-9</font></a><td><a href='javascript:popitup('Detail.aspx?ContainerNumber=MLKU 543349-6');'><font size=1>MLKU 543349-6</font></a><td><tr><a href='javascript:popitup('Detail.aspx?ContainerNumber=MLKU 543351-5');'><font size=1>MLKU 543351-5</font></a><td><a href='javascript:popitup('Detail.aspx?ContainerNumber=MLKU 543358-
3');'><font size=1>MLKU 543358-3</font></a><td><tr><a href='javascript:popitup('Detail.aspx?ContainerNumber=MLKU 543385-5');'><font size=1>MLKU 543385-5</font></a><td><a href='javascript:popitup('Detail.aspx?ContainerNumber=MLKU 543392-1');'><font size=1>MLKU 543392-1</font></a><td><tr><a href='javascript:popitup('Detail.aspx?ContainerNumber=MLKU 543393-7');'><font size=1>MLKU 543393-7</font></a><td><a href='javascript:popitup('Detail.aspx?ContainerNumber=OPTU 230532-6');'><font size=1>OPTU 230532-6</font></a><td><tr><a href='javascript:popitup('Detail.aspx?ContainerNumber=TIFU 148065-4');'><font size=1>TIFU 148065-4</font></a><td><a href='javascript:popitup('Detail.aspx?ContainerNumber=TIFU 148822-8');'><font size=1>TIFU 148822-8</font></a><td><tr><a href='javascript:popitup('Detail.aspx?ContainerNumber=TIFU 348106-9');'><font size=1>TIFU 348106-9</font></a><td><a href='javascript:popitup('Detail.aspx?ContainerNumber=TIFU 348151-5');'><font size=1>TIFU 348151-5</font></a><td><tr><a href='javascript:popitup('D
etail.aspx?ContainerNumber=TIFU 348390-3');'><font size=1>TIFU 348390-3</font></a><td></table>"
0
 
LVL 2

Author Comment

by:michael1174
ID: 22807196
this was my current javascript function
function popitup(url) {

	newwindow=window.open(url,'ISO Tank Container Information','height=200,width=150');

	if (window.focus) {newwindow.focus()}

	return false;

}

Open in new window

0
 
LVL 12

Accepted Solution

by:
techExtreme earned 500 total points
ID: 22807269
Hello,
I guess i found atleast one bug, notice your source renders anchor like this:

<a href='javascript:popitup('Detail.aspx?ContainerNumber=OPTU 230532-6');'><font size=1>OPTU 230532-6</font></a>

Notice there are single quotes after href=    and before ><font  i.e. javascript line is enclosed in single quotes and still inside the line single quotes are used : It is conflicting.

Instead of that, use double quotes for the outer quotes. I.e. your tag should be rendered like this:
<a href="javascript:popitup('Detail.aspx?ContainerNumber=OPTU 230532-6');"><font size=1>OPTU 230532-6</font></a>

Notice only difference is that there are double quotes outside i.e. after a href=  we have a double quote and before ending the tag we have a double quote .
WHerever you are constructing this string, do this minor change and you will see when you hover over the link, in the status bar you will see whole function name like javascript: popitup('....');  till the semicolon  which right now might be showing just "javascript:popitup("

Hope it helped.
Enjoy Coding!
0
 
LVL 2

Author Closing Comment

by:michael1174
ID: 31509978
Thank you for all your help, it's greatly appreciated!!! :)
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7850-Hex-Maze-Part-2.html), we'll extend the program by adding a depth-…
Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

708 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

16 Experts available now in Live!

Get 1:1 Help Now