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

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

    Posted 26 Jun 2012 Link to this post


    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
  2. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 26 Jun 2012 Link to this post

    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.
  3. Dorababu
    Dorababu avatar
    95 posts
    Member since:
    May 2012

    Posted 26 Jun 2012 Link to this post

    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.

  4. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 26 Jun 2012 Link to this post

    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.
  5. Dorababu
    Dorababu avatar
    95 posts
    Member since:
    May 2012

    Posted 27 Jun 2012 Link to this post

    If i make that on the next click I am unable to load the window again. 
  6. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 27 Jun 2012 Link to this post

    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.
  7. Dorababu
    Dorababu avatar
    95 posts
    Member since:
    May 2012

    Posted 27 Jun 2012 Link to this post

    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
  8. Dorababu
    Dorababu avatar
    95 posts
    Member since:
    May 2012

    Posted 27 Jun 2012 Link to this post

    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
  9. Dorababu
    Dorababu avatar
    95 posts
    Member since:
    May 2012

    Posted 27 Jun 2012 Link to this post

    On Escape I am unable to close the window
  10. Answer
    Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 27 Jun 2012 Link to this post

    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.
  11. Dorababu
    Dorababu avatar
    95 posts
    Member since:
    May 2012

    Posted 28 Jun 2012 Link to this post

    Thanks Proncy
Back to Top