ASP.NET HTML Editor - Knowledge Base

« Back to Knowledge Base list

Custom button for Image inserting, domain name in image path

Q:

I have made a custom button in your HTML Editor. This button shall open an ASPX page (filemanager.aspx) with 2 textboxes. The first textbox will hold a file-path, the second will hold a title-text for this file. When clicking “ok” I want an image to be inserted in the HTML Editor (with scr= textbox1.value and alt=textbox2.value).

I have 2 problems getting it to work correct:

  1. The image is not inserted in correct position. It is always inserted in the beginning / start of the Editor content (not at the cursor position).
  2. I want the image path to be the value of textbox1 (“/upload/TestImage.jpg”) without the domain name first (“http://localhost/Upload/TestImage.jpg”) as it is now.

Under you see the code I have made. It is based on some Obout examples (cs_Custom_ImageUpload_popup.aspx), but I guess I have forgotten some stuff. Hope you please can help me getting this to work, I have tried all I can think of but without luck. I will be so very thankful for your help!!!

------------------------------------------------------------
File 1, HTML Editor
------------------------------------------------------------

///Code front:///

<ed:Editor id="editor" PathPrefix="Editor_data/" Height="600" ShowQuickFormat="false" AutoFocus="false"
               Submit="false" FlashBrowse="myFlashBrowse.aspx" MediaBrowse="myMediaBrowse.aspx"
               ImageBrowse="myImageBrowse.aspx" UrlBrowse="myUrlBrowse.aspx" runat="server"
               Content='<%#DataBinder.Eval(Container.DataItem, "Content") %>'>
  <Buttons>

  <ed:HorizontalSeparator/>

  <ed:Custom OnClientClick="filemanager" ImageName="ed_upload_image_n.gif" ToolTip="Insert image" />

  </Buttons>
</ed:Editor>


<script type="text/JavaScript">
function filemanager(editor)
{
  var imageFileName = null;
  var imageFileTitle = null;

  function postback(doc,popup_iframe)
  {

  if(doc != null) // OK clicked

  {

  if(doc.getElementById("path").value != "")

  {

  imageFileName = doc.getElementById("path").value;

  imageFileTitle = doc.getElementById("title").value;

  editor.focusEditor();

  editor.InsertHTML("<img src=\""+imageFileName+"\" alt=\""+imageFileTitle+"\" title=\""+imageFileTitle+"\" />");


  //Close popup

  return true;

  }

  }

  }

  function init(doc,popup_iframe)
  {
  }

  editor.customPopup("popup_image_upload","Filemanager","Filemanager.aspx",postback,init, false, false);
}
</script>



------------------------------------------------------------
File 2 - Popup (Filemanager.aspx):
------------------------------------------------------------

///Code front:///

<input type=text id="path" name="path" style="width:100%" value="<%=imagePath %>">
<input type=text id="title" name="title" style="width:100%" value="<%=imageText %>">

///Code behind:///

public OboutInc.Editor.FieldsFiller image_filler;
public string imagePath = "/Upload/TestImage.jpg";
public string imageText = "This is some text";

private void Page_Load(object sender, EventArgs e)
{
  Page.Response.Write("<scr" + "ipt>");
  Page.Response.Write("var imageFileName = null;");
  Page.Response.Write("var imageFileTitle = null;");
  Page.Response.Write("imageFileName = \"" + imagePath + "\";");
  Page.Response.Write("imageFileTitle = \"" + imageText + "\";");
  Page.Response.Write("</scr" + "ipt>");
}


A:

1. JavaScript code should be corrected:

function filemanager(editor)
{
  var imageFileName = null;
  var imageFileTitle = null;

  function postback(doc,popup_iframe)
  {

  if(doc != null) // OK clicked

  {

  if(doc.getElementById("path").value != "")

  {

  imageFileName = doc.getElementById("path").value;

  imageFileTitle = doc.getElementById("title").value;


  // setTimeout trick is needed for the selected range be restored before image inserted !!!

  //

  setTimeout(function(){

  editor.focusEditor();

  editor.InsertHTML("<img src=\""+imageFileName+"\" alt=\""+imageFileTitle+"\" title=\""+imageFileTitle+"\" />");

  },100);


  //Close popup

  return true;

  }

  }

  }

  function init(doc,popup_iframe)
  {
  }

  editor.customPopup("popup_image_upload","Filemanager","Filemanager.aspx",postback,init, false, false);
}

2. RelImgUrls property should be set to “true”.
obout.com
obout.com Home
News
HTML Editor Home
HTML Editor Home
Why the best?
Download
Site Map
Examples - 80
Appearance - 10
Full button set
Lite button set
Custom button set
Design-mode textbox
How to fit into small space
Page maker
Default font
Initially without toolbar
Preview mode
"Read only" mode New
Content - 16
Read-only and custom tags
Shadow for Image
External image gallery
Upload images
Copy/paste formatting
Preview Document appearance
Keys used for editing
.NET validation
Documents Generator
Upload documents
Convert to PDF
FullHTML
Editor and database
Spell Checker - 3
Spell checking
Spell Checker dictionaries
Several dictionaries
Localization - 2
Localization
RTL support
Integration - 9
Inside Flyout
Inside Grid
Inside Window
With Color PickerNew
Google AJAX Language API New
Inside AJAX Page
Inside CallbackPanel
MultiView
Wizard
ASP.NET AJAX ControlToolkit - 5
Collapsible panel
Tabs
Editor in each TabPanel New
Timer
Modal popup
Server-Side API - 13
Content counters
Plain text length control
Show plain text
Enable editor on focus
Set caret position on load
Add CSS files New
Hide HTML Editor until needed
FixedToolBar
CSS file for quick format
Set HTML view on load
Enable browse button for images
Enable browse button for URLs
Disable Wait message New
Server-Side Events - 5
ClickSubmit event
ClickCancel event
ContentChanged event
CallbackContent
ClientCancel
Client-Side API - 10
Working with selected text
Set design/HTML view on load
Show/hide HTML Editor
Get/set content
Surround HTML
Insert HTML
Style selected content
Exec command
Query command
'Not Set' in dropdowns New
Customize - 17
Custom editor toolbar in VS
Custom fonts
Custom font sizes
How to add icons
Custom Popup Windows
Custom Buttons
Custom Context Menu
Popup Properties Disabling
Default Table Properties
Custom toggle button
Custom select button
Textarea popup
Custom 'Quote' button New
Show/hide submit button
Show/hide Design/HTML view
Show/hide quick format panel
Width & Height
Knowledge Base - 1
Knowledge Base
Documentation - 23
Server side
HTML Editor properties & events
HTML Editor inner properties
Custom toolbar
Custom fonts
Custom font sizes
Custom Context Menu
Dictionaries for spell checker
Hot keys definition
Disabling Context Menu items
Additional CSS files New
Client side
Main functions and interfaces
Custom Context Menu support
Custom Popup Window support
Top toolbar buttons' methods
State functions
Suppress Context Menu
Spelling dictionary
Dictionary structure
Affix rules
Phonetic rules
Generate phonetic code
How to add new word
Supported browsers
ChangeLog
Tutorials - 6
Using the correct path
Autosave implementation
Full custom buttons set
Editor_data for several sites
Use with database
Template XML file use New