Hi,
You can try the way below. I use a new HiddenField control to save the src value, so you can get it at server side.
- <%@ Page Language="VB" %>
- <%@ Register TagPrefix="RTE" Namespace="RTE" Assembly="RichTextEditor" %>
- <!DOCTYPE html>
-
- <script runat="server">
-
- Protected Sub btn_GetURL_Click(sender As Object, e As EventArgs)
- l1.Text=hf1.Value
- End Sub
- </script>
-
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head runat="server">
- <script type="text/javascript">
- var editor;
- var showed = false;
-
- function RichTextEditor_OnLoader(loader) {
- var config = loader._config;
- config.showtoolbar = false;
- config.showtoolbar_code = false;
- config.showbottombar = false;
- config.preloadplugins = "";
- var div = document.getElementById(config.containerid);
- div.style.display = "none";
- }
- function ShowEditorGallery() {
- showed = true;
- if (editor) {
- editor.ExecUICommand(null, "InsertGallery");
- }
- }
-
- function RichTextEditor_OnLoad(argeditor) {
- editor = argeditor;
- if (showed)
- ShowEditorGallery()
- }
-
- function RichTextEditor_OnTextChanged() {
- if (!showed) return;
- showed = false;
- var img = editor.GetPointNode();
- var editwin = editor.GetWindow();//added by ken
- var editdoc = editwin.document;//added by ken
- if (img && img.GetNameLower() == "img") {
- var src = img.GetAttribute("src");
- var width = editdoc.images[0].width;//added by ken
- var height = editdoc.images[0].height;//added by ken
- OnGetImageUrl(src, width, height);//changed by ken
- }
- editor.SetText("");
- }
- //changed by ken
- function OnGetImageUrl(src, width, height) {
- document.getElementById("result").innerHTML = "You selected : " + src + "<br/>" + "width : " + width + "<br/>" + "height : " + height;
- document.getElementById("<%= hf1.ClientID %>").value = src;
- }
-
- </script>
- </head>
- <body>
- <form id="form1" runat="server">
- <h1>Use RichTextEditor as image selector</h1>
- <p>
- </p>
- <div style="display: none;">
- <RTE:Editor runat="server" ID="Editor1" />
- </div>
- <br />
- <div>
- <button type="button" onclick="ShowEditorGallery();return false;">Select Image</button>
- </div>
- <br />
- <div id="result"></div>
- <asp:HiddenField ID="hf1" runat="server" />
- <asp:Button ID="btn_GetURL" runat="server" Text="get url at server side" OnClick="btn_GetURL_Click"/>
- <br />
- <asp:Label ID="l1" runat="server"></asp:Label>
- </form>
- </body>
- </html>
Regards,
Ken