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

unable to close radwindow manage from server side when controls inside updatepanel

10 Answers 188 Views
Window
This is a migrated thread and some comments may be shown as answers.
Dorababu
Top achievements
Rank 1
Dorababu asked on 26 Jun 2012, 09:30 AM

Hi all I have designed a radwindow manager which will have a dropdown and a textbox and a button which are placed inside a update panel.

Every thing works fine but on button click I am closing my window manager as follows

RadWindowManager1.Windows[0].VisibleOnPageLoad = false;

But this didn't work can some one help me this is my design and code

<telerik:RadWindowManager ID="RadWindowManager1" runat="server" Behavior="Default"
        InitialBehavior="None">
        <Windows>
            <telerik:RadWindow ID="RadWindow1" runat="server" Behaviors="Default" InitialBehaviors="None"
                OpenerElementID="btn" Width="650" Height="480" VisibleOnPageLoad="false">                   
                <ContentTemplate>
                    <asp:UpdatePanel ID="up" runat="server" OnUnload="up_Unload">
                    <Triggers>
                    <asp:AsyncPostBackTrigger ControlID="rdcmb" EventName="SelectedIndexChanged" />
                    <asp:AsyncPostBackTrigger ControlID="radbtn" EventName="Click" />
                    </Triggers>
                        <ContentTemplate>
                            <telerik:RadComboBox ID="rdcmb" runat="server" AutoPostBack="true" OnSelectedIndexChanged="sel">
                                <Items>
                                    <telerik:RadComboBoxItem Text="One" Value="One" />
                                    <telerik:RadComboBoxItem Text="Two" Value="Two" />
                                    <telerik:RadComboBoxItem Text="Three" Value="Three" />
                                    <telerik:RadComboBoxItem Text="Four" Value="Four" />
                                </Items>
                            </telerik:RadComboBox>
                            <telerik:RadTextBox ID="rdText" runat="server">
                            </telerik:RadTextBox>
                            <telerik:RadButton ID="radbtn" runat="server" Text="Save" OnClick="btn_Click">
                            </telerik:RadButton>
                        </ContentTemplate>
                    </asp:UpdatePanel>
                </ContentTemplate>
            </telerik:RadWindow>
        </Windows>
    </telerik:RadWindowManager>
    <telerik:RadButton ID="rdbtnwhAnother" Text="Add WithHolding" runat="server" ButtonType="LinkButton"
        OnClick="rdbtnwhAnother_Click">
    </telerik:RadButton>

Code 

protected void Page_Load(object sender, EventArgs e)
{
    if (!IsPostBack)
    {
        RadWindowManager1.Windows[0].VisibleOnPageLoad = false;
    }
}
 
protected void rdbtnwhAnother_Click(object sender, EventArgs e)
{
    RadWindowManager1.Windows[0].VisibleOnPageLoad = true;
}
 
protected void btn_Click(object sender, EventArgs e)
{
    RadWindowManager1.Windows[0].VisibleOnPageLoad = false;
}
 
protected void sel(object sender, EventArgs e)
{
    rdText.Text = rdcmb.SelectedItem.Text;
}
 
protected void up_Unload(object sender, EventArgs e)
{
    /* Cast sender as an updatePanel, and use reflection to invoke * * the page's scriptmanger registerUpdatePanel() method * * */
    //RadWindowManager1.Windows[0].VisibleOnPageLoad = false;
    UpdatePanel aUpdatePanel = sender as UpdatePanel;
 
    MethodInfo m = (
        from methods in typeof(ScriptManager).GetMethods(
            BindingFlags.NonPublic | BindingFlags.Instance
            )
        where methods.Name.Equals("System.Web.UI.IScriptManagerInternal.RegisterUpdatePanel")
        select methods).First<MethodInfo>();
 
    m.Invoke(ScriptManager.GetCurrent(aUpdatePanel.Page), new object[] { aUpdatePanel });
}

Can some one help me.

When my button is inside RadMultiPage I am even unable to load my RadWindowManager1 on button click

10 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 26 Jun 2012, 12:48 PM
Hi Dorababu,

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. Please take a look into this for more information.

Setting VisibleOnPageLoad property of RadWindow to false doesn't close the RadWindow. Please try the following code snippet to close the RadWindow.

C#:
protected void btn_Click(object sender, EventArgs e)
    {
        RadWindowManager1.Windows[0].VisibleOnPageLoad = false;
        RadWindowManager1.Windows[0].Visible = false;
    }

Hope this helps.

Thanks,
Princy.
0
Dorababu
Top achievements
Rank 1
answered on 26 Jun 2012, 12:54 PM
Didn't work if I click the button for multiple times I am getting the following error

Invalid postback or callback argument.  Event validation is enabled using <pages enableEventValidation="true"/> in configuration or <%@ Page EnableEventValidation="true" %> in a page.  For security purposes, this feature verifies that arguments to postback or callback events originate from the server control that originally rendered them.  If the data is valid and expected, use the ClientScriptManager.RegisterForEventValidation method in order to register the postback or callback data for validation.

0
Princy
Top achievements
Rank 2
answered on 27 Jun 2012, 02:44 AM
Hi Dorababu,

Try setting EnableEventValidation property of Page to false as follows.

ASPX:
<%@ Page Language="C#" AutoEventWireup="true"  EnableEventValidation="false" %>

Hope this helps.

Thanks,
Princy.
0
Dorababu
Top achievements
Rank 1
answered on 27 Jun 2012, 08:20 AM
If i make that on the next click I am unable to load the window again. 
0
Princy
Top achievements
Rank 2
answered on 27 Jun 2012, 11:13 AM
Hi Dorababu,

Following is the code snippet that I tried and which worked as expected at my end.

ASPX:
<telerik:RadWindow ID="rdwndw" runat="server" VisibleOnPageLoad="false">
   <Shortcuts>
      <telerik:WindowShortcut CommandName="CloseAll" Shortcut="Esc" />
   </Shortcuts>
   <ContentTemplate>
      <telerik:RadComboBox ID="RadComboBox1" runat="server" AutoPostBack="true" OnSelectedIndexChanged="sel1">
         <Items>
            <telerik:RadComboBoxItem Text="One" Value="One" />
            <telerik:RadComboBoxItem Text="Two" Value="Two" />
            <telerik:RadComboBoxItem Text="Three" Value="Three" />
            <telerik:RadComboBoxItem Text="Four" Value="Four" />
         </Items>
      </telerik:RadComboBox>
      <telerik:RadTextBox ID="RadTextBox1" runat="server">
      </telerik:RadTextBox>
      <telerik:RadButton ID="RadButton2" runat="server" Text="Save" OnClick="RadButton2_Click">
      </telerik:RadButton>
   </ContentTemplate>
</telerik:RadWindow>
<telerik:RadButton ID="rdbtnwhAnother" Text="Add WithHolding" runat="server" ButtonType="LinkButton" OnClick="rdbtnwhAnother_Click">
</telerik:RadButton>

C#:
protected void rdbtnwhAnother_Click(object sender, EventArgs e)
    {
        rdwndw.VisibleOnPageLoad = true;
        rdwndw.Visible = true;
    }
protected void RadButton2_Click(object sender, EventArgs e)
    {
        rdwndw.VisibleOnPageLoad = false;
        rdwndw.Visible = false;
    }
protected void sel1(object sender, EventArgs e)
    {
        RadTextBox1.Text = RadComboBox1.SelectedItem.Text;
    }

Hope this helps.

Thanks,
Princy.
0
Dorababu
Top achievements
Rank 1
answered on 27 Jun 2012, 11:26 AM
I had a question i.e assume if my text box is empty can I show the popup with the same window saying like textbox should not be empty
0
Dorababu
Top achievements
Rank 1
answered on 27 Jun 2012, 11:33 AM
This is my design I am having a radwindow and radwindowmanager as follows

<div>
        <telerik:RadWindowManager id="RadWindowManager1" runat="server">
        </telerik:RadWindowManager>
        <telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" runat="server" />
        <telerik:RadWindow ID="RadWindow2" runat="server" VisibleOnPageLoad="false">
            <Shortcuts>
                <telerik:WindowShortcut CommandName="CloseAll" Shortcut="Esc" />
            </Shortcuts>
            <ContentTemplate>
                <telerik:RadAjaxPanel ID="RadAjaxPanel1" runat="server" LoadingPanelID="RadAjaxLoadingPanel1">
                    <asp:Button runat="server" Text="Click" OnClick="democlick" ID="Button1" />
                </telerik:RadAjaxPanel>
            </ContentTemplate>
        </telerik:RadWindow>
        <telerik:RadWindow ID="RadWindow1" runat="server" VisibleOnPageLoad="false">
            <Shortcuts>
                <telerik:WindowShortcut CommandName="CloseAll" Shortcut="Esc" />
            </Shortcuts>
            <ContentTemplate>
                <asp:Button runat="server" Text="Click" OnClick="demo" ID="demo1" />
            </ContentTemplate>
        </telerik:RadWindow>
        <telerik:RadWindow ID="rdwndw" runat="server" VisibleOnPageLoad="false">
            <Shortcuts>
                <telerik:WindowShortcut CommandName="CloseAll" Shortcut="Esc" />
            </Shortcuts>
            <ContentTemplate>
                <telerik:RadComboBox ID="RadComboBox1" runat="server" AutoPostBack="true" OnSelectedIndexChanged="sel1">
                    <Items>
                        <telerik:RadComboBoxItem Text="One" Value="One" />
                        <telerik:RadComboBoxItem Text="Two" Value="Two" />
                        <telerik:RadComboBoxItem Text="Three" Value="Three" />
                        <telerik:RadComboBoxItem Text="Four" Value="Four" />
                    </Items>
                </telerik:RadComboBox>
                <telerik:RadTextBox ID="RadTextBox1" runat="server">
                </telerik:RadTextBox>
                <telerik:RadButton ID="RadButton2" runat="server" Text="Save" OnClick="RadButton2_Click">
                </telerik:RadButton>
            </ContentTemplate>
        </telerik:RadWindow>
        <telerik:RadButton ID="rdbtnwhAnother" Text="Add WithHolding" runat="server" ButtonType="LinkButton"
            OnClick="rdbtnwhAnother_Click">
        </telerik:RadButton>
    </div>

My code is as follows

protected void rdbtnwhAnother_Click(object sender, EventArgs e)
    {
        rdwndw.VisibleOnPageLoad = true;
 
    }
 
protected void RadButton2_Click(object sender, EventArgs e)
    {
        if (RadTextBox1.Text != string.Empty)
            rdwndw.VisibleOnPageLoad = false;
        else
        {
            rdwndw.VisibleOnPageLoad = false;
            string scriptstring = "radalert('You must save Employee Information to proceed further..', 250, 80,'Information');";
            //string javaScriptCode = "Sys.Application.add_load(function() {showRadConfirm(" + message + ");});";
            ScriptManager.RegisterStartupScript(this, this.GetType(), "radalert", scriptstring, false);
        }
 
    }
 
 protected void sel1(object sender, EventArgs e)
    {
        RadTextBox1.Text = RadComboBox1.SelectedItem.Text;
    }

I would like to show radwindowmanager as per written but i am not getting the required
0
Dorababu
Top achievements
Rank 1
answered on 27 Jun 2012, 11:36 AM
On Escape I am unable to close the window
0
Accepted
Princy
Top achievements
Rank 2
answered on 28 Jun 2012, 04:53 AM
Hi Dorababu,

Try the following code snippet to show RadAlert when RadTextBox1 is empty.

C#:
protected void RadButton2_Click(object sender, EventArgs e)
    {
        if (RadTextBox1.Text != string.Empty)
            rdwndw.VisibleOnPageLoad = false;
        else
        {
            rdwndw.VisibleOnPageLoad = false;
            string scriptstring = "<script language='javascript'>function f(){radalert('You must save Employee Information to proceed further..', 330, 210); Sys.Application.remove_load(f);}; Sys.Application.add_load(f);</script>";
            Page.ClientScript.RegisterStartupScript(this.GetType(), "radalert", scriptstring);
        }
    }

Please make sure that the RadWindow is inside the RadWindowManager to close the RadWindow on Esc keypress.

Thanks,
Princy.
0
Dorababu
Top achievements
Rank 1
answered on 28 Jun 2012, 08:36 AM
Thanks Proncy
Tags
Window
Asked by
Dorababu
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Dorababu
Top achievements
Rank 1
Share this question
or