Opening RadWindow conditionally on dropdown_SelectedIndexChanged

8 posts, 0 answers
  1. Kati
    Kati avatar
    46 posts
    Member since:
    Oct 2012

    Posted 22 Oct 2012 Link to this post

    I have a dropdownlist and when the user selects a certain item i would like to open up the radwindow.
    I have the following

    protected

     

     

    void ddlSentencing_SelectedIndexChanged(object sender, EventArgs e)

     

    {

     

     

     

        if (selectedVal == 2 || selectedVal == 3)

     

        {

            ddlSentencing.Attributes.Add(

     

    "onclick", "openRadWinNew(); return false;");

     

        }

    }

     

     

    function openRadWinNew() {

     

     

     

    var url = "Dialog.aspx";

     

     

     

    var oWnd = radopen(url, "ResponsePopup").setSize(500, 300)

     

    }

    it works but always only on second click, one step behind. Can ypu please help me fix this?

    Thanks

  2. Marin Bratanov
    Admin
    Marin Bratanov avatar
    5699 posts

    Posted 23 Oct 2012 Link to this post

    Hello Kati,

    You are only adding the handler when the dropdownlist posts back. You need to add it in the page markup or in the Page_Load/Page_Init events so that the client-side handler is available for the first click as well.


    Kind regards,
    Marin Bratanov
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
  3. Kati
    Kati avatar
    46 posts
    Member since:
    Oct 2012

    Posted 23 Oct 2012 Link to this post

    Thanks. I have changed my code to this but it is still always one step behind

     

     

    protected void Page_Load(object sender, EventArgs e)

     

    {

     

     

        if (SentencingID == 2 || SentencingID == 3)

     

        {

            ddlSentencing.Attributes.Add(

     

    "onchange", "openRadWinNew(); return false;");

     

        }

    }

    if the first item i select is 2 the popup does not open. If then I select 3 it opens but it thinks it's a 2

  4. Marin Bratanov
    Admin
    Marin Bratanov avatar
    5699 posts

    Posted 23 Oct 2012 Link to this post

    Hello Kati,

    If you want only certain items to open the RadWindow you can use the logic in the selectedIndexChanged event, but instead of adding handlers for the dropdownlist - simply initiate the show() call from the code-behind, as explained in this sticky thread: http://www.telerik.com/community/forums/aspnet-ajax/window/opening-radwindow-from-the-server.aspx.


    Greetings,
    Marin Bratanov
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
  5. Kati
    Kati avatar
    46 posts
    Member since:
    Oct 2012

    Posted 23 Oct 2012 Link to this post

    I have tried the code you pointed me to, but sadly I am geeting an error

    string script = "function f(){$find(\"" + RadWindow1.ClientID + "\").show(); Sys.Application.remove_load(f);}Sys.Application.add_load(f);"
        ScriptManager.RegisterStartupScript(Page, Page.GetType(), "key", script, true); 


    "'null' is null or not an object

     

    "

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

    Posted 24 Oct 2012 Link to this post

    Hi Kati,

    Here is the full code that I tried based on your scenario.
    aspx:
    <telerik:RadWindow ID="RadWindow1" runat="server" ></telerik:RadWindow>
    <asp:DropDownList ID="ddl" runat="server" AutoPostBack="true" onselectedindexchanged="ddl_SelectedIndexChanged">
      <asp:ListItem Value="1"></asp:ListItem>
      <asp:ListItem Value="2"></asp:ListItem>
      <asp:ListItem Value="3"></asp:ListItem>
      <asp:ListItem Value="4"></asp:ListItem>
      <asp:ListItem Value="5"></asp:ListItem>
    </asp:DropDownList>
    C#:
    protected void ddl_SelectedIndexChanged(object sender, EventArgs e)
    {
      if (ddl.SelectedValue.ToString() == "2" || ddl.SelectedValue.ToString() == "3")
      {
        string script = "function f(){$find(\"" + RadWindow1.ClientID + "\").show(); Sys.Application.remove_load(f);}Sys.Application.add_load(f);";
        ScriptManager.RegisterStartupScript(Page, Page.GetType(), "key", script, true); 
      }
    }

    Thanks,
    Princy.
  7. Harendra
    Harendra  avatar
    10 posts
    Member since:
    Jun 2013

    Posted 09 Jan in reply to Marin Bratanov Link to this post

    Hi, Although this post is quite old but i am facing the same issue. i have radwindow is bind to a button on its click it working properly. now coming to the issue part i want the same window to be called on page load, but only after it is validated against some conditions from database. Click is working fine but not able to call the radwindow on page load....
  8. Attila Antal
    Admin
    Attila Antal avatar
    591 posts

    Posted 13 Jan Link to this post

    Hi Harendra,

    Opening a RadWindow on the server is done the way it is described in that document posted by Marin.

    If the RadWindow does not open as expected, there might be other problems preventing it.

    I suggest that you open the browser's developer tools and monitor the console tab while testing the application. If you notice JavaScript errors, please eliminate them first. If there are no JavaScript errors, then you can try to register the ClientScript on the server according to the article and test the application again.

    Here is a Blog Post with tips to debug apps in the browser: Improve Your Debugging Skills with Chrome DevTools

    Ultimately, if you have not managed to fix the problem, please share all the details that will help us replicate the same exact problem. We will check the cause and tell you how to fix it.

    Regards,
    Attila Antal
    Progress Telerik

    Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Back to Top