General ImageField Question: Where to go from here
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();
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);
<%@ 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
>
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!