Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


window.open or AJAX Toolkit PopupControl Extender -- Which is best for this?

Posted on 2011-09-04
Medium Priority
Last Modified: 2012-05-12
I am getting confused as to the best way to proceed on this problem -- not a new event for me but still frustrating. I have a building reservation situation where I store building use information in a SQLServer Express database and display it on a calendar. What I want to be able to do is click on the day and have a popup form appear with a detail view of the building use data for that day. The user should be able to edit the data and save it to the database.

In searching for information on the PopupControlExtender I came across the window.open method of displaying another window. Here are my questions:
1. What is the best way to do what I want to do? An entirely different approach may be best. I don't know.
2. What options do I have if the user has disabled Java or disabled popups?

I am a true novice when it comes to web development. Examples and links to beginner level tutorials would be greatly appreciated.
Question by:rkulp
  • 3
  • 2

Accepted Solution

Gewgala earned 2000 total points
ID: 36481525
I would go with the PopupControlExtender, as that opens an in-page modal window (just a floating container such as a div) rather than window.open which opens a whole new browser window (a.k.a. pop up window that most people have blockers installed to prevent).

The trick to get links that execute javascript code to still execute when javascript is disabled, is to use the event.preventDefault() method in non-IE browsers, and event.returnValue = false; in IE.


<a href="myDetailsPage.aspx?id=5" onclick="showDetails(5, event)">Details</a>

Open in new window

Inside the showDetails JavaScript function you have:

function showDetails(buildingId, e)
     // put code here that programmatically executes/shows your PopupControlExtender
     // the particular link that calls this function in the above example passes in a buildingId of 5
     // which you can use to show specific data about building 5

     // after you show the pop up content via your PopupControlExtender, 
     // the following code will prevent the href="myDetailsPage.aspx" on the link from executing
     if (e.preventDefault)  // non IE browsers
           e.returnValue = false;  // IE browsers

Open in new window

With the above code, the link "Details" is set to go to the page "myDetailsPage.aspx?id=5".  The link also has an onclick event that points to a method that accepts the buildingId value as well as the event handler of the click event (the e parameter inside the javascript function).  Inside that function, you use the buildingId value in your display of the details pop up on the client.  That function continues to then stop execution of href value on the original link when the user clicked on it.  As a result, javascript was used to stop the browser from navigating to myDetailsPage.aspx?id=5.  

This works well because when JavaScript is disabled, the regular function of the link will not be stopped and the browser will instead navigate to myDetailsPage.aspx?id=5 where you can have code in that page that listens for a get parameter query string of "id" and use it's value to display building 5's content.


Author Comment

ID: 36483678

Thanks for your quick response. The situatuion is not quite what you have stated but theoretically equivalent. The user clicks on a date in the calendar and that date is what is needed for the query to show the details about the building. However, that difference leads to one more problem. How do I fire the PopupControlExtender from the Calendar.selectionChanged event rather than a button onClick event? That is, how do I execute showDetails from the calendar code behind? The only example I can find uses <asp:ModalPopupExtender> which I cannot find anywhere, either in VS2005 or VS2010. That control had a show method but the PopupControlExtender does not.

Author Comment

ID: 36484048

I found the <ajax:ModalPopupExtender> and can show the popup from the calendar's selectionchanged event. However, it is an empty panel except for a "close" button. It seems I have considerable work to do. I'll get back in a day or so to give you and update and, hopefully, close the question. Thanks for your help.

Author Closing Comment

ID: 36485390
Thanks for your excellent response. It was very clear, even to a novice.

Expert Comment

ID: 36486286
Glad I could help.

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
A while back, I ran into a situation where I was trying to use the calculated columns feature in SharePoint 2013 to do some simple math using values in two lists. Between certain data types not being accessible, and also with trying to make a one to…
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…
Suggested Courses

564 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