General ImageField Question: Where to go from here

Posted by Community Admin on 04-Aug-2018 16:32

General ImageField Question: Where to go from here

All Replies

Posted by Community Admin on 17-May-2012 00:00

Hi. I am pretty new to developing in Sitefinity and I have some very elementary questions about the ImageField control. I have created a user control that I added to a Backend page. Basically I would like to use the ImageField control for selecting and uploading images. The control displays properly and I can select images that are on the server. When I click my
 form submit button I would like to simply take the input and store it into a table that I have created. Pretty standard stuff. I am having trouble figuring out how to retrieve the URL of the image from the ImageField control during the post back. I figured it would be something like

String ImageURL = ImageSelector.Value.ToString();

However this returns an empty string. I have set the DataFieldType to String.

Here is my user control code behind:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
 
namespace SitefinityWebApp.Modules.Carousels.Admin
    public partial class CarouselCreateAdmin : System.Web.UI.UserControl
    
        protected void Page_Load(object sender, EventArgs e)
        
            // set the image selector type to use string (src)
            ImageSelector.DataFieldType = typeof(String);
 
            if(IsPostBack)
                Response.Write("Image URL: " + ImageSelector.Value);
            
        
 
    

and here is my .ascx code:

<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="CarouselCreateAdmin.ascx.cs" Inherits="SitefinityWebApp.Modules.Carousels.Admin.CarouselCreateAdmin" %>
<%@ Register Assembly="Telerik.Sitefinity" Namespace="Telerik.Sitefinity.Web.UI.Fields" TagPrefix="sf" %>
<div id="control-wrapper">
    <div class="text-wrap">
        <label class="sfTxtLbl">Select An Image:</label>
        <sf:ImageField ID="ImageSelector" runat="server" DisplayMode="Write" UploadMode="Dialog" DataFieldName="Image" />
    </div
</div>

I am developing for Sitefinity 4.4. I'm sure this is very basic but I am having trouble and have yet to find the answer in the forums. Any assistance would be most helpful. Thanks in advance.

Posted by Community Admin on 17-May-2012 00:00

the imagefield uses javascript to persist the data back to your widget property, and must do so through a control designer.

for a walkthrough using the imagefield in a control designer, take a look at this post, which also has a downloadable example project: Selecting Sitefinity 4 Content Inside Widget Designers

for more information about control designers take a look at this post: “Hello World” guide to custom Sitefinity Widgets & ControlDesigners

hope this is helpful!

This thread is closed