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

Opening RadWindow conditionally on dropdown_SelectedIndexChanged

7 Answers 224 Views
Window
This is a migrated thread and some comments may be shown as answers.
Kati
Top achievements
Rank 1
Kati asked on 22 Oct 2012, 04:17 PM
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

7 Answers, 1 is accepted

Sort by
0
Marin Bratanov
Telerik team
answered on 23 Oct 2012, 10:06 AM
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.
0
Kati
Top achievements
Rank 1
answered on 23 Oct 2012, 10:27 AM
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

0
Marin Bratanov
Telerik team
answered on 23 Oct 2012, 10:34 AM
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.
0
Kati
Top achievements
Rank 1
answered on 23 Oct 2012, 01:40 PM
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

 

"

0
Princy
Top achievements
Rank 2
answered on 25 Oct 2012, 04:44 AM
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.
0
Harendra
Top achievements
Rank 1
answered on 09 Jan 2021, 06:12 AM
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....
0
Attila Antal
Telerik team
answered on 13 Jan 2021, 02:40 PM

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/.

Tags
Window
Asked by
Kati
Top achievements
Rank 1
Answers by
Marin Bratanov
Telerik team
Kati
Top achievements
Rank 1
Princy
Top achievements
Rank 2
Harendra
Top achievements
Rank 1
Attila Antal
Telerik team
Share this question
or