Why on first click my radwindow is not getting closed

3 posts, 0 answers
  1. Dorababu
    Dorababu avatar
    95 posts
    Member since:
    May 2012

    Posted 29 Jun 2012 Link to this post

    I have written a code to close radwindow on button click this is my design 

    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="radwndAjax.aspx.cs" Inherits="radwndAjax" %>
     
    <%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <head runat="server">
        <title></title>
    </head>
    <body>
        <form id="form1" runat="server">
        <telerik:RadScriptManager ID="Script1" runat="server">
        </telerik:RadScriptManager>
        <div>
            <telerik:RadCodeBlock ID="radcode" runat="server">
                <script type="text/javascript">
                    function OpenSuperSeeding() {
                        var wnd = $find("<%= RadWindow1.ClientID%>");
                        wnd.Close();
                    }
                </script>
            </telerik:RadCodeBlock>
            <telerik:RadButton ID="btn" runat="server" OnClick="btn_Click" Text="Open">
            </telerik:RadButton>
            <telerik:RadWindow runat="server" ID="RadWindow1">
                <ContentTemplate>
                    <asp:UpdatePanel ID="Updatepanel1" runat="server" UpdateMode="Conditional">
                        <ContentTemplate>
                            <asp:Button ID="Button1" Text="Click for AJAX" runat="server" OnClick="Button1_Click" />
                            <br />
                            <asp:Label ID="Label1" Text="I will be updated" runat="server" />
                        </ContentTemplate>
                    </asp:UpdatePanel>
                </ContentTemplate>
            </telerik:RadWindow>
            <asp:Label ID="Label2" Text="I will not be updated" runat="server" />
        </div>
        </form>
    </body>
    </html>

    My code is as follows

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
     
    public partial class radwndAjax : System.Web.UI.Page
    {
        bool m_flag = true;
        protected void Page_Load(object sender, EventArgs e)
        {
     
        }
     
        protected void btn_Click(object sender, EventArgs e)
        {
            RadWindow1.VisibleOnPageLoad = true;
        }
     
        protected void Button1_Click(object sender, EventArgs e)
        {
            if (m_flag)
            {
                RadWindow1.VisibleOnPageLoad = false;
                Button1.OnClientClick = "OpenSuperSeeding(); return false;";
            }
            else
            {
                Label1.Text = DateTime.Now.ToString();
                Label2.Text = DateTime.Now.ToString();
            }
        }
    }

    But on first click radwindow is not getting closed, on the second click it is getting closed can some one help me..
  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 02 Jul 2012 Link to this post

    Hello,

    Generally placing the RadWindow in an update panel is not recommended, because the rendered HTML is moved from its original location in the markup. This will most often result in the expected functionality simply not working.
    aspx:
    <telerik:RadButton ID="btn" runat="server" OnClick="btn_Click" Text="Open">
    </telerik:RadButton>
    <telerik:RadWindow runat="server" ID="RadWindow1" ReloadOnShow="false">
      <ContentTemplate>
         <asp:Button ID="Button1" Text="Click for AJAX" runat="server" OnClick="Button1_Click" />
         <br />
         <asp:Label ID="Label1" Text="I will be updated" runat="server" />
      </ContentTemplate>
    </telerik:RadWindow>
    <asp:Label ID="Label2" Text="I will not be updated" runat="server" />
    JS:
    <script type="text/javascript">
        function OpenSuperSeeding() {
            debugger;
            var wnd = $find("<%= RadWindow1.ClientID%>");
            wnd.Close();
        }
    </script>
    C#:
    bool m_flag = true;
        protected void Page_Load(object sender, EventArgs e)
        {
     
        }
        protected void btn_Click(object sender, EventArgs e)
        {
            RadWindow1.VisibleOnPageLoad = true;
        }
     
        protected void Button1_Click(object sender, EventArgs e)
        {
            if (m_flag)
            {
                RadWindow1.VisibleOnPageLoad = false;
                Button1.OnClientClick = "OpenSuperSeeding(); return false;";
            }
            else
            {
                Label1.Text = DateTime.Now.ToString();
                Label2.Text = DateTime.Now.ToString();
            }
        }

    Thanks,
    Shinu.
  3. rdmptn
    rdmptn avatar
    72 posts
    Member since:
    Aug 2011

    Posted 02 Jul 2012 Link to this post

    Actually your problem is that you add the OnClientClick handler in the server click handler itself. You need to add it in the markup or in Page_Init. With your current logic the client click takes place, not logic is attached to it, the button posts back, it server click handler is hit, client click logic is added, so the next time you click it there is client click handler.
Back to Top