|
|||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||
|
Announcements
Chapters
Services
Feature Zones
|
IntroductionAsynchronous JavaScript and XML (AJAX) -- Jesse James Garrett was the creator of the term AJAX -- enables a rich user interface experience for web applications. I'm not going to tell you the plus and minus points about AJAX, but this will help you to inform yourself about AJAX's background. Here I demonstrate the usage of the Modal Popup control, one of the AJAX controls that comes with AJAX Toolkit 1.0. The reason that I was motivated to write this article about the Modal Popup control is that I came across a situation where, by selecting a dynamically populated list, it was desired to display more details about the selection as a modal dialog box. The challenge is that I was developing a web application and I had only two days to achieve this. Thanks to AJAX Modal Popup, I made it. Otherwise, I couldn't make it within two days because there would be too much researching and tons of JavaScripts. I think this article will help those who are in the same situation. BackgroundThe scenario is a real world scenario: when a user selects a court from the drop down list, he needs to view more information about that court without redirecting to a new page. Also, until he closes the dialog, he should not be able to edit background items on the form. Using the CodeBefore trying this demo, please do these prerequisites:
System.Web.Script.Services.ScriptService attribute to the web service class. It should look like this:
[System.Web.Script.Services.ScriptService]
public class CourtService : System.Web.Services.WebService
{
}
Create a web method that fetches the data. It should return a string and have a string parameter; this is mandatory. The string parameter is the dynamic key that is used to fetch data on demand. In our case, it's the dropdown's selected item. [WebMethod]
public string GetCourt(string contextKey)
{
//TODO. Method body
}
If this method returns a string, how are we going to get all the data that we want to display? It's a simple, but tricky. On the popup control we are using a web server control, usually the Label control, to display data. Since this method returns a string, format your data to a line of string. As in the demo project I want to bold the column name, so I can wrap column the name with The completed method follows. [WebMethod]
public string GetCourt(string contextKey)
{
if (contextKey == "")
return "";
m_courtData = m_court.GetACourtByID(int.Parse(contextKey));
DataSet1.CourtRow _courtRow = m_courtData.Rows[0] as DataSet1.CourtRow;
System.Text.StringBuilder _sb = new System.Text.StringBuilder();
_sb.Append("<b>Court Code: </b>").Append(_courtRow.CourtID);
_sb.Append("<br/>");
_sb.Append("<b>Judge Name: </b>").Append(_courtRow.Judge);
_sb.Append("<br/>");
_sb.Append("<b>Court More Info:</b><br/>");
_sb.Append(_courtRow.Info);
return _sb.ToString();
}
Pay attention to the following markup code in the Default.aspx page. Table 1 describes these properties respectively. <cc1:ModalPopupExtender ID="mpeCourt" runat="server"
OkControlID="btnDlgOK"
PopupControlID="pnlPopup"
TargetControlID="btnDummy"
DynamicServicePath="CourtService.asmx"
DynamicServiceMethod="GetCourt"
DynamicControlID="lblInfo"
BackgroundCssClass="modal"
DropShadow="true">
</cc1:ModalPopupExtender>
Table 1: Property Descriptions
As you can see, we use an instance of button for protected void drpCourt_SelectedIndexChanged(object sender, EventArgs e)
{
if (drpCourt.SelectedIndex != 0)
{
mpeCourt.DynamicContextKey = drpCourt.SelectedValue;
// Display the dialog
mpeCourt.Show();
}
}
Notice that pnlPopup.Style.Add("display", "none");
History
|
||||||||||||||||||||||||||||||||||||||||