show and hide radwindow from server code

4 posts, 0 answers
  1. EJ
    EJ avatar
    37 posts
    Member since:
    Jun 2012

    Posted 09 Jun 2010 Link to this post

    EJ

    Posted on 13 minutes ago

    i have two situations as I listed earlier:

    1) needing to display a messagebox modal that shows info and has ok button - radalert seems to be the ticket here if I can get it to work

    2) needing to display a usercontrol within a modal window inside of my browser window that is not a popup window - radwindow seems to be the thing to use here - but i need to have two buttons outside of the usercontrol that have "add" or "cancel" - the cancel button can just close the window - the "Add" button needs to call a public method on the usercontrol and if that returns true then it closes the window and passes back a value of what was added (guid or string) otherwise it does nothing and the radwindow continues to be displayed

    here's the structure of my page

    my code for this is running in a user control that is embedded in a page that has a masterpage

    my masterpage has the scriptmanager component

    the user control generally is structured like so:

    <asp:UpdatePanel ID="MyUpdatePanel" runat="server">
        <ContentTemplate>
            <asp:FormView ID="MyFormView" runat="server" DefaultMode="Edit" DataSourceID="MyObjectDataSource">
                <EditItemTemplate>
    <asp:Panel ID="Panel1" runat="server" DefaultButton="ReaderLinkButton">
                                <asp:LinkButton ID="MyLinkButton" runat="server" OnClick="MyLinkButton_Click">My Link</asp:LinkButton>
    </EditItemTemplate>
            </asp:FormView>
        </ContentTemplate>
    </asp:UpdatePanel>
    <telerik:RadWindowManager ID="RadWindowManager1" runat="server">
    <Windows>
            <telerik:RadWindow ID="MyDialogRadWindow" runat="server" Modal="True">
                <ContentTemplate>
                    <asp:Label ID="MyLabel" runat="server" Text=""></asp:Label>
                    <uc:MyControl ID="MySpecialControl" runat="server" />
                    <asp:Button ID="DialogCancelButton" runat="server" Text="Cancel" OnClick="DialogCancelButton_Click"
                        Visible="false" />
                    <asp:Button ID="DialogOkButton" runat="server" Text="Ok" OnClick="DialogOkButton_Click" />
                </ContentTemplate>
            </telerik:RadWindow>
    </Windows>
    </telerik:RadWindowManager>
    </ContentTemplate>
    </asp:UpdatePanel>

    and my code behind for the linkbutton is

    protected void MyLinkButton_Click(object sender, EventArgs e)
            {

    // this was my attempts at the radalert

    //                        string script = @"
    //                                    function f() {
    //                                        radalert('" + returnValues[1] + @"');                        
    //                                    }
    //                                Sys.Application.remove_load(f);
    //                                Sys.Application.add_load(f);";

                           string script = @"radalert('" + returnValues[1] + @"',200,200);";                        
                            Page.ClientScript.RegisterStartupScript(typeof(string), "radalert", script, true);
    }

    i read various posts about this but there does not seem to be a definite method to open/show or close/hide the radwindow that is located inside of a updatepanel inside a user control.

    I tried this and it does not work

            private void ShowDialog() 
            { 
             // define the name and type of the client scripts on the page 
                string csname = "showDialog"
                // get a clientscriptmanager reerence from the page class 
                ClientScriptManager cs = Page.ClientScript; 
                // check to see if the startup script is already registered 
                if (!cs.IsStartupScriptRegistered(csname)) 
                { 
                    string script = @" 
                    <script language='javascript'
                        function showDialog(){ 
                            var oWnd = $find('" + MyDialogRadWindow.ClientID + @"'); 
                            oWnd.show(); 
                            Sys.Application.remove_load(showDialog); 
                        };  
                        Sys.Application.add_load(showDialog); 
                    </script>"; 
                    cs.RegisterStartupScript(typeof(string), csname, script); 
                } 
            } 
     
            private void HideDialog() 
            { 
                string csname = "hideDialog"
                // get a clientscriptmanager reerence from the page class 
                ClientScriptManager cs = Page.ClientScript; 
                // check to see if the startup script is already registered 
                if (!cs.IsStartupScriptRegistered(csname)) 
                { 
                    string script = @" 
                    <script language='javascript'
                        function hideDialog(){ 
                            var oWnd = $find('" + MyDialogRadWindow.ClientID + @"'); 
                            oWnd.Close(); 
                            Sys.Application.remove_load(hideDialog); 
                        };  
                        Sys.Application.add_load(hideDialog); 
                    </script>"; 
                    cs.RegisterStartupScript(typeof(string), csname, script); 
                } 
            } 

    i tried this but it did not help calling it server side

    i tried doing the ajax sample here but that did not work either
    how do I do this?

  2. Fiko
    Admin
    Fiko avatar
    1406 posts
    Member since:
    Sep 2012

    Posted 15 Jun 2010 Link to this post

    Hello EJ,

    I have already answered your support ticket. For convenience I have attached the solution to this thread as well.

    Kind regards,
    Fiko
    the Telerik team


    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.

  3. EJ
    EJ avatar
    37 posts
    Member since:
    Jun 2012

    Posted 16 Jun 2010 Link to this post

    the functionality does not work as you said when the button and the logic behind a button are ALL inside of a user control.

    our applications put all functionality in user controls and use pages only as the point of aggregation of the user controls with little code in the page and master page

    enclosed is a copy of your project modified to show the structure of our application. the only thing that is missing is that yours is not using master pages and ours is - but it still fails without even using master pages

    here's the structure

    masterpage
         page
              usercontrol
              usercontrol
                  button to trigger server-side functionality

    as you see the functionality as you coded it works in the master page or in the page itself but if you put the button and the register script functionality all into a server side method in the user control the radalert is never called

    so your sample works but when i adapt it to being inside of a user control it does - so either the control has bugs or we have to take a different approach when it's inside of a user control

    <%@ Control Language="C#" AutoEventWireup="true" CodeFile="EmbeddedUserControl.ascx.cs" 
        Inherits="EmbeddedUserControl" %> 
     
    <asp:UpdatePanel ID="UpdatePanel2" runat="server"
        <ContentTemplate> 
            <asp:Button ID="ShowAlertButton" runat="server" Text="Fail Showing RadAlertDialog From Inside Embedded User Control calling Page javascript" 
                OnClick="ShowAlertButton_Click" /> 
        </ContentTemplate> 
    </asp:UpdatePanel> 
     
    using System; 
    using System.Collections.Generic; 
    using System.Linq; 
    using System.Web; 
    using System.Web.UI; 
    using System.Web.UI.WebControls; 
     
    public partial class EmbeddedUserControl : System.Web.UI.UserControl 
        protected void Page_Load(object sender, EventArgs e) 
        { 
     
        } 
     
        protected void ShowAlertButton_Click(object sender, EventArgs e) 
        { 
            this.ShowUserControlAlertDialog("Radalert from the server"); 
        } 
     
        private void ShowUserControlAlertDialog(string alertText) 
        { 
            string script = string.Format("showAlertDialog('{0}');", alertText); ; 
            ScriptManager.RegisterStartupScript(this, this.GetType(), "KEY", script, true); 
        } 

  4. Fiko
    Admin
    Fiko avatar
    1406 posts
    Member since:
    Sep 2012

    Posted 22 Jun 2010 Link to this post

    Hi EJ,

    I have already answered your support ticket. For convenience, however, I have pasted a part of my answer:

    "The problem in the implemented solution is that the ScriptManager.RegisterStartupScript, in your case, requires the Page object to be passed as parameter, not the user control (this object is the UserControl itself). This is why, could you please change the script registration to looks like this:

    ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "KEY", script, true);

     
    In addition, I have found a little problem in the JavaScript declaration inside the EmbeddedUserControl.ascx file - a "=" sing is added between the script and type words:
    <script = type="text/javascript">
               function showUserControlAlertDialog(alertText) {
                   function f() {
                       Sys.Application.remove_load(f);
                       radalert(alertText);
                   }
                   Sys.Application.add_load(f);
               }
       </script>

    You need to remove it in order to avoid further potential problems."


    Sincerely yours,
    Fiko
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items

Back to Top