Solved

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

Posted on 2011-09-04
5
398 Views
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.
0
Comment
Question by:rkulp
  • 3
  • 2
5 Comments
 
LVL 7

Accepted Solution

by:
Gewgala earned 500 total points
Comment Utility
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.

Example:

<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.preventDefault();
     else
           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.

0
 
LVL 1

Author Comment

by:rkulp
Comment Utility
Gewgala,

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.
0
 
LVL 1

Author Comment

by:rkulp
Comment Utility
Gewgala,

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.
0
 
LVL 1

Author Closing Comment

by:rkulp
Comment Utility
Thanks for your excellent response. It was very clear, even to a novice.
0
 
LVL 7

Expert Comment

by:Gewgala
Comment Utility
Glad I could help.
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

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…
jQuery is a JavaScript library that greatly simplifies JavaScript programming. AJAX is an acronym formed from "Asynchronous JavaScript and XML."  AJAX refers to any communication between client and server, when the human client does not observe a…
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…

771 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

10 Experts available now in Live!

Get 1:1 Help Now