I am having a page where i use a radeditor.
What i would like to do is when i click the image gallery and select an image except the editor, a text box with an id 'txtSelectedImage' needs to be updated.
Is there any way to get this done?
Thanks in advance
1 Answer, 1 is accepted
0
Rumen
Telerik team
answered on 11 Jun 2008, 12:04 PM
Hi Paris,
If I understand you correctly, you need to update a textbox when the user inserts an image via the Image manager.
If this is your scenario then you can use the following code:
<asp:ScriptManager ID="ScriptManager1" runat="server" />
<script type="text/javascript">
function OnClientPasteHtml(sender, args)
{
var commandName = args.get_commandName();
var value = args.get_value();
if (commandName == "ImageManager")
{
//See if an img has an alt tag set
var div = document.createElement("DIV");
//Do not use div.innerHTML as in IE this would cause the image's src or the link's href to be converted to absolute path.
//This is a severe IE quirk.
Telerik.Web.UI.Editor.Utils.setElementInnerHtml(div,value);
//Now check if there is alt attribute
var img = div.firstChild; var myInput = $get('txtSelectedImage');
if (myInput)
{ myInput.value = img.src;
args.set_value(div.innerHTML);
}
}
}
</script>
<telerik:radeditor runat="server" ID="RadEditor1" OnClientPasteHtml="OnClientPasteHtml" ImageManager-ViewPaths="~/" ImageManager-UploadPaths="~/"
></telerik:radeditor>
<input type="text" id="txtSelectedImage" />
You can find more information about the OnClientPasteHtml event in this live example: OnClientPasteHtml.