The Telerik RadImageManager is a handy control for uploading / managing and selecting images, however it is embedded into the Rich Text editor control (RadEditor). To use it as a standalone tool you can use the following method:
In the front end view do the following:
Additional code in the aspx file:
In the code behind set up a function to initialise the Image Manager with appropriate property values. This can be reused for multiple Dialog Openers
In the front end view do the following:
- Add into Web.Config the telerik dialog handler declaration
- Declare a RadDialogOpener
- Declare a hidden field to store the domain path to be used in the URL
- Declare a textbox to store the URL
- Create an image icon to launch the Image Manager.
<system.web>
<httpHandlers>
....
<add path="Telerik.Web.UI.DialogHandler.aspx" verb="*" type="Telerik.Web.UI.DialogHandler, Telerik.Web.UI"/>
</httpHandlers>
</system.web>
Additional code in the aspx file:
<telerik:RadDialogOpener runat="server" ID="dop1" />
<asp:HiddenField ID="hfImageServer" runat="server" ClientIDMode="Static" />
<asp:TextBox ID="tbxImageURL" runat="server" Width="500" Text='<%#Bind("ImageURL")%>' MaxLength="256" ClientIDMode="Static" />
<img src="/images/icon/photo.png" onclick="$find('<%= dop1.ClientID %>').open('ImageManager', {CssClasses: []});return false;" width="16" height="16" alt="Image Manager for Image URL" title="Image Manager" />
In the code behind set up a function to initialise the Image Manager with appropriate property values. This can be reused for multiple Dialog Openers
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
SetupImageManager(dop1)
End Sub
Private Sub SetupImageManager(ByVal dop As RadDialogOpener)
hfImageServer.Value = "http://www.mydomain.com"
Dim imageManagerParameters As New FileManagerDialogParameters()
imageManagerParameters.ViewPaths = New String() {"~/UploadFolderName"}
imageManagerParameters.UploadPaths = New String() {"~/UploadFolderName"}
imageManagerParameters.DeletePaths = New String() {"~/UploadFolderName"}
'imageManagerParameters.MaxUploadFileSize = 102400
'imageManagerParameters.SearchPatterns = new string[] { "*.jpg" };
Dim imageManager As New DialogDefinition(GetType(ImageManagerDialog), imageManagerParameters)
imageManager.ClientCallbackFunction = "ImageManagerFunction" & dop.ID
imageManager.Width = Unit.Pixel(600)
imageManager.Height = Unit.Pixel(500)
imageManager.Parameters("ExternalDialogsPath") = "~/ExternalDialogs/"
dop.DialogDefinitions.Add("ImageManager", imageManager)
Dim imageEditorParameters As New FileManagerDialogParameters()
imageEditorParameters.ViewPaths = New String() {"~/UploadFolderName"}
imageEditorParameters.UploadPaths = New String() {"~/UploadFolderName"}
imageEditorParameters.DeletePaths = New String() {"~/UploadFolderName"}
'imageEditorParameters.MaxUploadFileSize = 102400
Dim imageEditor As New DialogDefinition(GetType(ImageEditorDialog), imageEditorParameters)
imageEditor.Width = Unit.Pixel(600)
imageEditor.Height = Unit.Pixel(500)
dop.DialogDefinitions.Add("ImageEditor", imageEditor)
End Sub
In the Javascript file have a callback function to populate the text field value
function ImageManagerFunctiondop1(sender, args) {
if (!args) {
alert('No file was selected!');
return false;
}
var txt = $get('tbxImageURL');
var path = args.value.getAttribute("src", 2);
txt.value = $('#hfImageServer').val() + path;
}
No comments:
Post a Comment