Hi,
I am trying to uses a Modal Dialog Control that loads a UserControl into the ContentArea dyamically ( ie another control on the page selects the UserControl to load into the Dialiog). The dialog is this displayed using the Server side Show() method.
I am using this techique to keep the size of the the page to a minimum during the initial load and provide a consistent look and feel to the page as the user accesses "pick lists" and "edits content" in the Modal Dialog Control.
The Dialog appears as expected, and the embedded user control functions correctly - in my test case the dialog contains a selection form and displays the results in a Grid. The DynamicControlsPlaceHolder is derive from the standard PlaceHolder and simply saves and restores the viewState of any controls placed in the container. This appears to be working fine.
If the user Cancels the dialog using the X image or pressing the Esc key the dialog disappears as expected.
However I need a means to progamatically dismiss the dialog when the user selects an item from the Grid().
The Dialog.CancelButton and Dialog.AcceptButton seem to be intended for this purpose; My challenge is to figure out how to attach them to the Dynamic User Control (where the button names may differ).
Any Help would be greatly appreciated.
Here are some code snippets -- the Test Page :
Code: HTML/ASPX
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="test.aspx.cs" Inherits="ecWebsite.Dialogs.test" %>
<%@ Register Assembly="ecWebsite" Namespace="ecControls" TagPrefix="cc1" %>
<%@ Register Assembly="EO.Web" Namespace="EO.Web" TagPrefix="eo" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Button ID="Button3" runat="server" Text="Pick Subscriber"
onclick="pickSubscriber" />
<eo:CallbackPanel ID="CallbackPanel1" runat="server" GroupName="group1">
<asp:Label ID="lTest" runat="server" Text=""></asp:Label>
</eo:CallbackPanel>
<eo:Dialog ID="picker" runat="server" BackColor="#EBEBEB"
Height="320px" Width="600px" CloseButtonUrl="00070301" ControlSkinID="None"
HeaderHtml="Dialog Title" >
<HeaderStyleActive CssText="padding-right: 3px; padding-left: 8px; font-weight: bold; font-size: 10pt; background-image: url(00020213); padding-bottom: 3px; color: white; padding-top: 0px; font-family: 'trebuchet ms';" />
<BorderImages BottomBorder="00020212" BottomLeftCorner="00020207"
BottomRightCorner="00020208" LeftBorder="00020210" RightBorder="00020211"
TopBorder="00020209" TopLeftCorner="00020201" TopLeftCornerBottom="00020203"
TopLeftCornerRight="00020202" TopRightCorner="00020204"
TopRightCornerBottom="00020206" TopRightCornerLeft="00020205" />
<FooterStyleActive CssText="padding-right: 4px; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; padding-top: 4px; font-family: tahoma" />
<ContentTemplate>
<eo:CallbackPanel ID="pickerPanel" runat="server"
OnExecute="pickerExecute"
ChildrenAsTriggers="true" GroupName="group1">
<cc1:DynamicControlsPlaceholder ID="DCP" runat="server" ControlsWithoutIDs="Persist">
</cc1:DynamicControlsPlaceholder>
</eo:CallbackPanel>
</ContentTemplate>
<ContentStyleActive CssText="padding-right: 4px; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; padding-top: 4px; font-family: tahoma" />
</eo:Dialog>
</div>
</form>
</body>
</html>
The Code Behind:
Code: C#
protected void pickerExecute(object sender, EO.Web.CallbackEventArgs e)
{
string controlName = (string)Session["usercontrol"];
switch (controlName)
{
case "pickSubscriber":
pickSubscriber p = (pickSubscriber)DCP.Controls[0];
switch (p.result)
{
case ecUserControl.dialogResult.Cancelled:
DCP.Controls.Clear();
lTest.Text = "Cancelled";
return;
case ecUserControl.dialogResult.Ok:
DCP.Controls.Clear();
lTest.Text = "Selected SubscriberId=" + mySession.SelectedSubscriberId.ToString();
break;
case ecUserControl.dialogResult.Unknown:
lTest.Text = "Unknown";
// picker.Show();
break;
}
break;
default:
return;
}
}
protected void pickSubscriber(object sender, EventArgs e)
{
showPicker("Select Subscriber", "pickSubscriber.ascx");
}
protected void showPicker(string title, string filename)
{
DCP.Controls.Clear();
Control dialog = LoadControl(filename);
DCP.Controls.Add(dialog);
picker.HeaderHtml = title;
picker.Show();
}
Here is the User Control (pickSubscriber.ascx):
Code: HTML/ASPX
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="pickSubscriber.ascx.cs" Inherits="ecWebsite.Dialogs.pickSubscriber" %>
<%@ Register Assembly="EO.Web" Namespace="EO.Web" TagPrefix="eo" %>
<script type="text/javascript" language="javascript">
function OnItemCommand(grid, itemIndex, colIndex, commandName)
{
grid.raiseItemCommandEvent(itemIndex, commandName)
}
</script>
<div Id="searchDiv" class="input-form" runat="server">
<fieldset>
<asp:Label ID="Label1" runat="server" Text="Search" AssociatedControlID="tSearch"></asp:Label>
<asp:TextBox ID="tSearch" Width="30em" runat="server"></asp:TextBox>
</fieldset>
<fieldset>
<asp:Label ID="Label2" runat="server" Text="Search Method" AssociatedControlID="lSearchMethod"></asp:Label>
<asp:DropDownList ID="lSearchMethod" runat="server" Width="20em">
<asp:ListItem Text="By Name" Value="N" Selected="True" />
<asp:ListItem Text="By SubscriberCode" Value="C" />
<asp:ListItem Text="By ABN" Value="A" />
<asp:ListItem Text="By Phone Number" Value="P" />
</asp:DropDownList>
</fieldset>
<fieldset>
<asp:Button ID="bSearch" runat="server" Text="Search" onclick="bSearch_Click" />
<asp:LinkButton ID="bCancel" runat="server" onclick="bCancel_Click">Cancel</asp:LinkButton>
</fieldset>
<fieldset>
<asp:Label ID="lError" runat="server" Text=""></asp:Label>
</fieldset>
</div>
<div id="resultsDiv" runat="server" visible="false">
<eo:Grid ID="GridResults" runat="server" Width="600" Height="300"
AllowPaging="true" PageSize="10" KeyField="SubscriberId" SkinId="GridSkin"
ClientSideOnItemCommand="OnItemCommand">
<Columns>
<eo:ButtonColumn ButtonType="LinkButton" ButtonText="Select" CommandName="select" />
<eo:StaticColumn DataField="SubscriberCode" HeaderText="Code" width="100" AllowSort="true"/>
<eo:StaticColumn DataField="SubscriberName" HeaderText="Name" width="300" AllowSort="true"/>
<eo:StaticColumn DataField="Phone" HeaderText="Phone" Width="100" AllowSort="true"/>
<eo:StaticColumn DataField="Address" HeaderText="Address" Width="400" AllowSort="true"/>
</Columns>
</eo:Grid>
<asp:Button ID="bNewSearch" runat="server" Text="New Search"
onclick="bNewSearch_Click" />
<asp:LinkButton ID="bCancel2" runat="server" onclick="bCancel2_Click">Cancel</asp:LinkButton>
</div>
And the Code behind for the User Control (pickSubscriber.ascx.cs):
Code: C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ecDAL.EntityClasses;
using ec;
namespace ecWebsite.Dialogs
{
public partial class pickSubscriber : ecUserControl
{
protected void Page_Load(object sender, EventArgs e)
{
initUserControl("pickSubscriber");
GridResults.ItemCommand += new EO.Web.GridCommandEventHandler(this.GridResults_ItemCommand);
}
protected void bSearch_Click(object sender, EventArgs e)
{
string searchText = tSearch.Text.Trim();
ecHelper.searchMethod searchMethod;
switch (lSearchMethod.SelectedValue)
{
case "N":
searchMethod = ecHelper.searchMethod.byName;
break;
case "C":
searchMethod = ecHelper.searchMethod.byCode;
break;
default:
lError.Text = "Sorry, this search method is not currently implemented";
return;
}
SubscriberEntity[] subscribers = myHelper.getSubscribers(searchText, searchMethod, myUI);
if (subscribers.Length == 0)
{
lError.Text = "Sorry, No Subscribers matched your search criteria";
return;
}
GridResults.DataSource = subscribers;
GridResults.DataBind();
searchDiv.Visible = false;
resultsDiv.Visible = true;
}
protected void bNewSearch_Click(object sender, EventArgs e)
{
lError.Text = "";
searchDiv.Visible = true;
resultsDiv.Visible = false;
}
protected void bCancel_Click(object sender, EventArgs e)
{
result = dialogResult.Cancelled;
}
protected void bCancel2_Click(object sender, EventArgs e)
{
result = dialogResult.Cancelled;
}
private void GridResults_ItemCommand(Object sender, EO.Web.GridCommandEventArgs e)
{
if (e.CommandName == "select")
{
int i = e.Item.Index;
mySession.SelectedSubscriberId = (int)GridResults.Items[i].Key;
result = dialogResult.Ok;
}
}
}
}