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

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

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
"

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

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