Implement the page for insert.
Again CSK offers the "ContentAddPage" class to disburden our adding task. In order to claim this facility, we have to name child controls of the content- skin (AudioVideos_AddAudioVideo.ascx) in a particular manner so that the override protected void ContentAddPage InitializeSkin(Control skin) method can grasp the child controls and wire them with suitable event-handlers. We have created the "AddAudioVideo" class (see Figure 8) to control the content-skin.
namespace ASPNET.StarterKit.Communities.AudioVideos
{
using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using ASPNET.StarterKit.Communities;
//*********************************************************************
//
// AddAudioVideo Class
//
// Represents the Add Link page. Enables users to list new Broadcastlinks.
//
//*********************************************************************
public class AddAudioVideo : ContentAddPage
{
string _skinFileName = "AudioVideos_AddAudioVideo.ascx";
string _sectionContent = "ASPNET.StarterKit.Communities.AudioVideos.AudioVideoSection";
TextBox txtUrl;
TextBox txtTitle;
TextBox txtDescription;
TextBox txtWidth;
TextBox txtHeight;
TopicPicker dropTopics;
AudioVideoTitle previewLinkTitle;
BriefDescription previewDescription;
DisplayTopic previewTopic;
RadioButton rbVideo;
RadioButton rbAudio;
//*********************************************************************
//
// SkinLoadAV
//
// The skin load event happens after a page skin has been loaded.
// Here, we grab the necessary controls from the page skin.
//
//*********************************************************************
void SkinLoadAV(Object s, SkinLoadEventArgs e)
{
txtTitle = (TextBox)GetControl(e.Skin,"txtTitle");
txtUrl = (TextBox)GetControl(e.Skin,"txtUrl");
txtDescription = (TextBox)GetControl(e.Skin,"txtDescription");
txtWidth=(TextBox)GetControl(e.Skin,"txtWidth");
txtHeight=(TextBox)GetControl(e.Skin,"txtHeight");
dropTopics = (TopicPicker)GetControl(e.Skin, "dropTopics");
previewLinkTitle = (AudioVideoTitle)GetControl(e.Skin, "previewLinkTitle");
previewDescription = (BriefDescription)GetControl(e.Skin, "previewDescription");
previewTopic = (DisplayTopic)GetControl(e.Skin, "previewTopic" );rbVideo =
(RadioButton)GetControl(e.Skin,"rbVideo");
rbAudio =(RadioButton)GetControl(e.Skin,"rbAudio");
rbVideo.GroupName="AudioVideo";
rbAudio.GroupName="AudioVideo";
}
//*********************************************************************
//
// PreviewLink Method
//
// When previewing a link, we want to transfer everything from
// the text boxes to the labels.
//
//*********************************************************************
void PreviewLink(Object s, EventArgs e)
{
previewLinkTitle.Text = txtTitle.Text;
previewLinkTitle.Url = txtUrl.Text;
previewDescription.Text = txtDescription.Text;
if (objSectionInfo.EnableTopics)
previewTopic.Name = dropTopics.SelectedItem.Text;
}
//*********************************************************************
//
// SubmitAudioVideo Method
//
// This method is raised by clicking the Add button in the
udioVideos_AddAudioVideo.ascx
//. It inserts an Audio-Video content to the database
//
/*********************************************************************
void SubmitAudioVideo(Object s, EventArgs e)
{
if (Page.IsValid)
{
// Get Topic
int topicID = -1;
if (objSectionInfo.EnableTopics)
topicID = Int32.Parse(dropTopics.SelectedItem.Value);
// Check moderation status
int moderationStatus = 1;
if (objSectionInfo.EnableModeration && !objUserInfo.MayModerate)
moderationStatus = 0;
// Content type
bool bVideo=(this.rbVideo.Checked?true:false);
short sHeight=Convert.ToInt16(txtHeight.Text);
short sWidth=Convert.ToInt16(txtWidth.Text);
// Insert
int contentPageID = AudioVideoUtility.AddAudioVideoLink
(
objSectionInfo.ID,
objUserInfo.Username,
txtTitle.Text,
txtUrl.Text,
bVideo,
sWidth,
sHeight,
txtDescription.Text,
moderationStatus,
topicID
);
// Show warning message if moderation enabled
if (objSectionInfo.EnableModeration && !objUserInfo.MayModerate)
Context.Response.Redirect(CommunityGlobals.CalculatePath("Messages_Message.aspx?
essage=moderation"));
// Otherwise, redirect to default page and send notifications
Context.Server.ScriptTimeout = 10 * 60;
Context.Response.Redirect(CommunityGlobals.CalculatePath("Default.aspx"), false);
Context.Response.Flush();
Context.Response.Close();
NotifyUtility.SendNotifications(objSectionInfo.ID, contentPageID, txtTitle.Text, objUserInfo.Username);
Context.Response.End();
}
}
//*********************************************************************
//
// AddAudioVideo Constructor
//
// Calls the base SkinnedCommunityControl constructor
// and assigns the default page skin.
//
//*********************************************************************
public AddAudioVideo() : base()
{
// Assign a default skin file name
SkinFileName = _skinFileName;
// Not specified
SectionContent = _sectionContent;
// Wire-up event handlers
this.SkinLoad += new SkinLoadEventHandler(SkinLoadAV);
this.Preview += new PreviewEventHandler(PreviewLink);
this.Submit += new SubmitEventHandler(SubmitAudioVideo);
}
}
}
Figure 8 (Class AddAudioVideo)
We have used the following statement to register this page.
/* register AudioVideo_AddAudioVideo.aspx*/
Insert INTO Community_NamedPages
(
namedpage_path ,
namedpage_pageContent ,
namedpage_title ,
namedpage_description ,
namedpage_sortOrder ,
namedpage_isVisible ,
namedpage_name ,
namedPage_menuID
)
VALUES
(
'/AudioVideos_AddAudioVideo.aspx',
'ASPNET.StarterKit.Communities.AudioVideos.AddAudioVideo',
'Adds an AudioVideo record',
'Enables users to add a BroadCast Link',
0,
1,
'Add a AudioVideo content',
0
)
Go
Create a page to represent a particular audio-video content.
We have created the " AudioVideos_AudioVideo" class and the "AudioVideos_AudioVideo.ascx" to display a particular Audio-Video content. The "AudioVideos_AudioVideo" class is derived from the "ContentItemPage" class and you can see from figure 9 that we have initialized the inherited properties "_skinFilename" and "_getContentItem". The ContentItemPage .OnInit(EventArgs e) uses the supplied callback method(AudioVideoUtility.GetAudioVideo) to retrieve the requested content and saves it into the memory.
override protected void OnInit(EventArgs e)
{
ContentInfo _contentInfo = GetContentItem(objUserInfo.Username, objPageInfo.ID);
Context.Items["ContentInfo"] = _contentInfo;
}
namespace namespace ASPNET.StarterKit.Communities.AudioVideos
{
using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using ASPNET.StarterKit.Communities;
//*********************************************************************
//
// AudioVideo Class
//
// Represents an individual AudioVideo content.
//
// _skinFileName = the name of the skin to use for this section
//
// _getContentItem = the name of the method that retrieves the content item
//
//*********************************************************************
public class AudioVideo : ContentItemPage
{
string _skinFileName = "AudioVideos_AudioVideo.ascx";
GetContentItemDelegate _getContentItem = new GetContentItemDelegate
AudioVideoUtility.GetAudioVideo);
//*********************************************************************
//
// Article Constructor
//
// Assigns skin and contentItems method to base ContentItemPage class
//
//*********************************************************************
public AudioVideo() : base()
{
SkinFileName = _skinFileName;
GetContentItem = _getContentItem;
}
}
}
( Source code for the ItemAVTitle class )
Join the conversation! Your thoughts help the community grow.