I am using the Telerik MVC controls (which at first glance are impressive) to build an MVC3 Razor application, and have a question about the Window control. I am trying to assign an ID to the Window when I create it from JavaScript so that I may reference it at any time using JQuery … $(‘WindowID’) … but can’t seem to be able to do so.
In short, here is my window:
var windowElement = $.telerik.window.create({
title: "Window opened from JS",
html: "<strong>Inserting an image...</strong>",
contentUrl: '',
modal: false,
resizable: false,
draggable: true,
scrollable: false,
width: 150,
onClose: function () { }
})
I would like to later, from some other random button or event, be able to move, resize, or close the Window by using it’s ID. The problem is, I haven’t been able to assign the Window any ID when creating it in JavaScript.
Note:
When I create the Window in the Razor view, I can assign a “Name” to the Window which DOES allow me to do exactly what I want to. However, I need to be able to create the Window in JavaScript. I guess I could create a bunch of Windows in Razor, then Hide/Show them as needed, but I would like that to be a last resort.
Ok, for anybody else interested, I eventually figured this out …
After creating my window in JavaScript (like this):
I used the .attr() jQuery method to assign the ‘id’ attribute of the Window (like this):
And that did the trick.
Note: Of course, I needed to have the jQuery library referenced for this to work …