Welcome Guest Search | Active Topics | Sign In | Register

Modal Dialog vs Dynamic UserControls Options
BP
Posted: Tuesday, September 15, 2009 2:38:50 AM
Rank: Member
Groups: Member

Joined: 8/27/2009
Posts: 10
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;
            }
        }
    }
}
eo_support
Posted: Tuesday, September 15, 2009 9:20:55 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,194
Hi,

You can do it either on the server side or on the client side. The key for both approaches is to get a reference of the dialog object.

On the server side you can walk up the Parent chain until you find the dialog. Then set its IntialState to Hidden to hide the dialog. Unless you use AJAX to load your dialog content (thus the dialog itself is not updated at all), this should work for you.

On the client side you can call close the dialog with the following code:

Code: JavaScript
eo_GetObject("Dialog1").close();


You can place this code inside your OnItemCommand handler. But depending on your scenario, you may need to delay the call with setTimeout:

Code: JavaScript
setTimeout(function()
   {
        eo_GetObject("Dialog1").close();
   }, 100);


Hope this helps.

Thanks!


You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.