This is a migrated thread and some comments may be shown as answers.

Why on first click my radwindow is not getting closed

2 Answers 33 Views
Window
This is a migrated thread and some comments may be shown as answers.
Dorababu
Top achievements
Rank 1
Dorababu asked on 29 Jun 2012, 09:13 AM
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 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 1
answered on 02 Jul 2012, 07:11 AM
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.
0
rdmptn
Top achievements
Rank 1
answered on 02 Jul 2012, 08:21 AM
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.
Tags
Window
Asked by
Dorababu
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 1
rdmptn
Top achievements
Rank 1
Share this question
or