Hi, the content of the textarea "reComment" is not being recognized, it returns empty, any ideas? thanks
// CODE
<telerik:RadCodeBlock ID="RadCodeBlock1" runat="server"> <script type="text/javascript"> var currentLoadingPanel = null; var btSubmit = null; function RequestStart(sender, args) { currentLoadingPanel = $find("<%= RadAjaxLoadingPanel1.ClientID%>"); btSubmit = "<%= panlcomments.ClientID %>"; //show the loading panel over the updated control currentLoadingPanel.show(btSubmit); } function ResponseEnd() { //hide the loading panel and clean up the global variables currentLoadingPanel.hide(btSubmit); //clear btSubmit.SetHtml(""); currentLoadingPanel = null; btSubmit = null; } </script> </telerik:RadCodeBlock> <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server"> <AjaxSettings> <telerik:AjaxSetting AjaxControlID="btSubmit"> <UpdatedControls> <telerik:AjaxUpdatedControl ControlID="newCommentLiteral" LoadingPanelID="RadAjaxLoadingPanel1" /> <telerik:AjaxUpdatedControl ControlID="panlcomments" LoadingPanelID="RadAjaxLoadingPanel1" /> </UpdatedControls> </telerik:AjaxSetting> </AjaxSettings> <ClientEvents OnRequestStart="RequestStart" OnResponseEnd="ResponseEnd" /> </telerik:RadAjaxManager> <telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" runat="server" BackgroundPosition="Center" Skin="Vista"> </telerik:RadAjaxLoadingPanel> <asp:Literal ID="existingComments" runat="server"></asp:Literal> <asp:Literal ID="newCommentLiteral" runat="server"></asp:Literal> <!-- on masque le control pour les anonymes --> <asp:Panel ID="panlcomments" runat="server"> <div class="exp-comment-message"><asp:Label ID="lblMessage" Text="Messages :" runat="server"></asp:Label></div> <telerik:RadEditor ID="reComment" runat="server" EditModes="Design" ToolbarMode="ShowOnFocus" ToolsWidth="170px" Width="350px" Height="100px" > <Tools> <telerik:EditorToolGroup> <telerik:EditorTool Name="Bold" /> <telerik:EditorTool Name="Italic" /> <telerik:EditorTool Name="StrikeThrough" /> <telerik:EditorTool Name="Underline" /> <telerik:EditorTool Name="InsertUnorderedList" /> <telerik:EditorTool Name="InsertOrderedList" /> </telerik:EditorToolGroup> </Tools> </telerik:RadEditor> <span class="exp-bout-comm"><asp:Button ID="btSubmit" runat="server" Text="Valider" OnClick="btSubmit_Click" CssClass="Exp-Comment-Submit"/></span> </asp:Panel>
// CODE
protected override void OnInit(EventArgs e) { Page.Init += delegate(object sender, EventArgs e_Init) { if (RadScriptManager.GetCurrent(Page) == null) { RadScriptManager sMgr = new RadScriptManager(); Page.Form.Controls.AddAt(0, sMgr); } string formOnSubmitAtt = this.Page.Form.Attributes["onsubmit"]; try { if (!string.IsNullOrEmpty(formOnSubmitAtt) && formOnSubmitAtt == "return _spFormOnSubmitWrapper();") { Page.Form.Attributes["onsubmit"] = "_spFormOnSubmitWrapper();"; } } catch { } try { if (btSubmit == null) btSubmit = this.FindControl("btSubmit") as Button; if (reComment == null) reComment = this.FindControl("reComment") as RadEditor;
8 Answers, 1 is accepted
0
Hello Renato,
Thank you for the provided code. If I have understood correctly, you are attempting to get/set the Editor's content via reComment.Content property and it is not being recognized, is that correct?
I have run several scenarios with the sample code you have provided us, but unfortunately, the provided server-side code was not enough to reproduce the described issue. Furthermore, I could not find a reference to the editor's content in it and, for this reason, I cannot determine the exact location at which the issue is raised.
Just for the test, I have attempted to and succeeded at getting/setting the Editor's content in both the Init and the Load event of the page.
Could you please provide us with sample code reproducing the issue, so that we can further investigate where and why the problem is appearing? You can refer to the following article for more information on how to isolate it: Isolating a problem in a sample project.
We will be looking forward to receiving feedback from you.
Regards,
Ivaylo
Telerik
Thank you for the provided code. If I have understood correctly, you are attempting to get/set the Editor's content via reComment.Content property and it is not being recognized, is that correct?
I have run several scenarios with the sample code you have provided us, but unfortunately, the provided server-side code was not enough to reproduce the described issue. Furthermore, I could not find a reference to the editor's content in it and, for this reason, I cannot determine the exact location at which the issue is raised.
Just for the test, I have attempted to and succeeded at getting/setting the Editor's content in both the Init and the Load event of the page.
Could you please provide us with sample code reproducing the issue, so that we can further investigate where and why the problem is appearing? You can refer to the following article for more information on how to isolate it: Isolating a problem in a sample project.
We will be looking forward to receiving feedback from you.
Regards,
Ivaylo
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
0

Renato
Top achievements
Rank 1
answered on 24 Jul 2013, 08:09 AM
Hi Ivaylo, thanks for the help... I am sending the code.
USER CONTROL (Comments.ascx)
<%@ Control Language="C#" Inherits="Expertime.PublishingComments.Library.Controls.Comments, Expertime.PublishingComments.Library, Version=1.0.0.0, Culture=neutral, PublicKeyToken=6b9c9c28502002f7" %>
<%@ Register TagPrefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls"
Assembly="Microsoft.SharePoint, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI, Version=2013.2.611.45, Culture=Neutral, PublicKeyToken=121fae78165ba3d4" %>
<%@Register TagPrefix="SharePointPortalControls" Namespace="Microsoft.SharePoint.Portal.WebControls" Assembly="Microsoft.SharePoint.Portal, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<
style
type
=
"text/css"
>
/* The following CSS needs to be copied to the page to produce textbox-like RadEditor */ .reWrapper_corner, .reWrapper_center {
display: none !important;
}
.reLeftVerticalSide, .reRightVerticalSide, .reToolZone, .reToolCell {
background: white !important;
}
.reContentCell {
border-width: 0 !important;
}
.RadEditor {
filter: chroma(color=c2dcf0);
}
</
style
>
<
telerik:RadCodeBlock
ID
=
"RadCodeBlock1"
runat
=
"server"
>
<
script
type
=
"text/javascript"
>
var currentLoadingPanel = null;
var btSubmit = null;
function RequestStart(sender, args) {
currentLoadingPanel = $find("<%= RadAjaxLoadingPanel1.ClientID%>");
btSubmit = "<%= panlcomments.ClientID %>";
//show the loading panel over the updated control
currentLoadingPanel.show(btSubmit);
}
function ResponseEnd() {
//hide the loading panel and clean up the global variables
currentLoadingPanel.hide(btSubmit);
//clear
btSubmit.SetHtml("");
currentLoadingPanel = null;
btSubmit = null;
}
</
script
>
</
telerik:RadCodeBlock
>
<
div
class
=
"ftv-wp-title"
>
<
asp:Literal
runat
=
"server"
ID
=
"HeaderTitle"
></
asp:Literal
>
</
div
>
<
telerik:RadAjaxManager
ID
=
"RadAjaxManager1"
runat
=
"server"
>
<
AjaxSettings
>
<
telerik:AjaxSetting
AjaxControlID
=
"btSubmit"
>
<
UpdatedControls
>
<
telerik:AjaxUpdatedControl
ControlID
=
"newCommentLiteral"
LoadingPanelID
=
"RadAjaxLoadingPanel1"
/>
<
telerik:AjaxUpdatedControl
ControlID
=
"panlcomments"
LoadingPanelID
=
"RadAjaxLoadingPanel1"
/>
</
UpdatedControls
>
</
telerik:AjaxSetting
>
</
AjaxSettings
>
<
ClientEvents
OnRequestStart
=
"RequestStart"
OnResponseEnd
=
"ResponseEnd"
/>
</
telerik:RadAjaxManager
>
<
telerik:RadAjaxLoadingPanel
ID
=
"RadAjaxLoadingPanel1"
runat
=
"server"
BackgroundPosition
=
"Center"
Skin
=
"Vista"
>
</
telerik:RadAjaxLoadingPanel
>
<
div
class
=
"ftv-content-social ftv-type2"
>
<
div
class
=
"ftv-comments"
>
<
a
class
=
"ftv-entry-comments"
><
asp:Label
runat
=
"server"
ID
=
"NbCommentsLbl"
/></
a
>
</
div
>
<
div
class
=
"ftv-notes"
>
<
a
>Note</
a
>
<
SharePointPortalControls:AverageRatingFieldControl
ID
=
"PageRatingControl"
FieldName
=
"AverageRating"
runat
=
"server"
/>
</
div
>
</
div
>
<
div
class
=
"Exp-Comments"
id
=
"ExpComments"
>
<
asp:Literal
ID
=
"existingComments"
runat
=
"server"
></
asp:Literal
>
</
div
>
<
asp:Literal
ID
=
"newCommentLiteral"
runat
=
"server"
></
asp:Literal
>
<!-- on masque le control pour les anonymes -->
<
asp:Panel
ID
=
"panlcomments"
runat
=
"server"
>
<
div
class
=
"exp-comment-message"
style
=
"display: none;"
>
<
asp:Label
Visible
=
"false"
ID
=
"lblMessage"
Text
=
"Messages :"
runat
=
"server"
></
asp:Label
></
div
>
<
div
class
=
"ftv-wp-title ftv-reagir"
>laissez un commentaire</
div
>
<
div
class
=
"ftv-reagir-comment"
>
<
telerik:RadEditor
ID
=
"reComment"
runat
=
"server"
EditModes
=
"Design"
ToolbarMode
=
"ShowOnFocus"
ToolsWidth
=
"170px"
Width
=
"412px"
Height
=
"72px"
>
<
Tools
>
<
telerik:EditorToolGroup
>
<
telerik:EditorTool
Name
=
"Bold"
/>
<
telerik:EditorTool
Name
=
"Italic"
/>
<
telerik:EditorTool
Name
=
"StrikeThrough"
/>
<
telerik:EditorTool
Name
=
"Underline"
/>
<
telerik:EditorTool
Name
=
"InsertUnorderedList"
/>
<
telerik:EditorTool
Name
=
"InsertOrderedList"
/>
</
telerik:EditorToolGroup
>
</
Tools
>
</
telerik:RadEditor
>
<
span
class
=
"exp-bout-comm"
>
<
asp:Button
ID
=
"btSubmit"
runat
=
"server"
Text
=
"Valider"
OnClick
=
"btSubmit_Click"
/></
span
>
<%--<
span
class
=
"exp-bout-comm"
><
asp:Button
ID
=
"btSubmit"
runat
=
"server"
Text
=
"Valider"
OnClick
=
"btSubmit_Click"
CssClass
=
"Exp-Comment-Submit"
/></
span
>--%>
</
div
>
</
asp:Panel
>
<
asp:Panel
ID
=
"pnelAnonyme"
runat
=
"server"
>
</
asp:Panel
>
CODE BEHIND (Comments.cs)
using
System;
using
System.Collections.Generic;
using
System.Linq;
using
System.Text;
using
System.Web;
using
Microsoft.SharePoint;
using
Microsoft.SharePoint.Publishing;
using
System.Web.UI.WebControls;
using
Telerik.Web.UI;
using
System.Data;
using
System.Web.UI;
namespace
Expertime.PublishingComments.Library.Controls
{
public
partial
class
Comments : System.Web.UI.UserControl
{
#region Controls
protected
Button btSubmit;
protected
RadEditor reComment;
protected
Literal existingComments;
protected
GridView gv1;
protected
Literal newCommentLiteral;
protected
Label lblMessage;
protected
Panel panlcomments;
protected
Panel pnelAnonyme;
private
string
_ValidationGroupId;
private
ValidationSummary _ErrorContainer;
private
ScriptManager _AjaxManager;
#endregion
#region vars & cons
const
string
CommentListUrl =
"ExpertimePublishingComments"
, CommentListTitle =
"Expertime Comments"
;
const
string
ExpertimePublishingCommentSiteFeatureId =
"68af5cec-59a1-4105-97a7-3fb7b68fbf46"
;
const
string
FieldName_ListItemId =
"ListItemId"
, FieldName_CommentBody =
"CommentBody"
;
#endregion
#region properties
public
ScriptManager AjaxManager
{
get
{
return
_AjaxManager; }
set
{ _AjaxManager = value; }
}
#endregion
protected
override
void
OnInit(EventArgs e)
{
Page.Init +=
delegate
(
object
sender, EventArgs e_Init)
{
if
(ScriptManager.GetCurrent(Page) ==
null
)
{
ScriptManager sMgr =
new
ScriptManager();
Page.Form.Controls.AddAt(0, sMgr);
}
string
formOnSubmitAtt =
this
.Page.Form.Attributes[
"onsubmit"
];
try
{
if
(!
string
.IsNullOrEmpty(formOnSubmitAtt) && formOnSubmitAtt ==
"return _spFormOnSubmitWrapper();"
)
{
Page.Form.Attributes[
"onsubmit"
] =
"_spFormOnSubmitWrapper();"
;
}
}
catch
{ }
try
{
if
(btSubmit ==
null
)
btSubmit =
this
.FindControl(
"btSubmit"
)
as
Button;
if
(reComment ==
null
)
reComment =
this
.FindControl(
"reComment"
)
as
RadEditor;
if
(existingComments ==
null
)
existingComments =
this
.FindControl(
"existingComments"
)
as
Literal;
if
(gv1 ==
null
)
gv1 =
this
.FindControl(
"gv1"
)
as
GridView;
if
(newCommentLiteral ==
null
)
newCommentLiteral =
this
.FindControl(
"newCommentLiteral"
)
as
Literal;
GetExistingComments();
}
catch
(Exception exc)
{
existingComments.Text =
string
.Format(
"<span class=\"Exp-Error\">{0}</span>"
, exc.Message);
}
if
(SPContext.Current.Web.CurrentUser ==
null
)
{
panlcomments.Visible =
false
;
pnelAnonyme.Visible =
true
;
}
else
{
panlcomments.Visible =
true
;
pnelAnonyme.Visible =
false
;
}
};
base
.OnInit(e);
}
protected
override
void
CreateChildControls()
{
base
.CreateChildControls();
if
(!
this
.Controls.Contains(_ErrorContainer))
{
_ValidationGroupId = Guid.NewGuid().ToString();
_ErrorContainer =
new
ValidationSummary();
_ErrorContainer.ID =
"_ErrorContainer"
;
_ErrorContainer.ValidationGroup = _ValidationGroupId;
_ErrorContainer.BorderStyle = BorderStyle.Solid;
_ErrorContainer.BorderWidth = Unit.Pixel(3);
_ErrorContainer.BorderColor = System.Drawing.Color.Red;
this
.Controls.Add(_ErrorContainer);
}
Literal HeaderTitle =
this
.FindControl(
"HeaderTitle"
)
as
Literal;
if
(HeaderTitle ==
null
)
throw
new
ArgumentNullException(
"le controle HeaderTitle n'existe pas"
);
if
(HttpContext.Current.User.Identity.IsAuthenticated)
HeaderTitle.Text =
"Réagir"
;
else
{
HeaderTitle.Text =
"<div class='ftv-wp-title ftv-title-separator'>Réagir</div>"
+
"<div class='ftv-offline'><a><h6>Connectez-vous</h6> pour réagir</a></div>"
;
}
}
private
void
GetExistingComments()
{
Guid siteId = SPContext.Current.Site.ID, webId = SPContext.Current.Web.ID;
SPSecurity.RunWithElevatedPrivileges(
delegate
()
{
using
(SPSite elevatedSite =
new
SPSite(siteId))
{
using
(SPWeb elevatedWeb = elevatedSite.OpenWeb(webId))
{
try
{
string
prefixUrl = elevatedWeb.ServerRelativeUrl ==
"/"
?
"/"
: elevatedWeb.ServerRelativeUrl +
"/"
;
SPList commentList = elevatedWeb.GetList(prefixUrl + CommentListUrl);
SPQuery query =
new
SPQuery();
string
queryString = @"<OrderBy>
<FieldRef Name=
""
Created
""
Ascending=
""
True
""
/>
</OrderBy>
<Where>
<Eq>
<FieldRef Name=
""
ListItemId
""
/>
<Value Type=
""
Text
""
>{0}</Value>
</Eq>
</Where>";
query.Query =
string
.Format(queryString, SPContext.Current.ListItem.UniqueId.ToString());
SPListItemCollection items = commentList.GetItems(query);
StringBuilder sb =
new
StringBuilder();
var NbCommentsLbl =
this
.FindControl(
"NbCommentsLbl"
)
as
Label;
if
(NbCommentsLbl ==
null
)
throw
new
ArgumentNullException(
"le controle NbCommentsLbl n'existe pas"
);
if
(items.Count <= 1)
NbCommentsLbl.Text = String.Format(
"{0} commentaire"
, items.Count.ToString());
else
NbCommentsLbl.Text = String.Format(
"{0} commentaires"
, items.Count.ToString());
// SPField fieldListItemId = commentList.Fields.GetFieldByInternalName(FieldName_ListItemId);
SPField fieldCommentBody = commentList.Fields.GetFieldByInternalName(FieldName_CommentBody);
SPField fieldCreatedBy = commentList.Fields.GetFieldByInternalName(
"Author"
);
SPField fieldCreated = commentList.Fields.GetFieldByInternalName(
"Created"
);
foreach
(SPListItem item
in
items)
{
sb.Append(
"<div class=\"Exp-Comment\">"
);
sb.Append(
"<div class=\"Exp-Comment-Header\">"
);
sb.Append(
"<div class=\"Exp-Comment-Author\">"
);
SPFieldUserValue fieldValue = fieldCreatedBy.GetFieldValue(item[fieldCreatedBy.Id].ToString())
as
SPFieldUserValue;
string
userDisplayName = fieldValue.User.Name;
sb.AppendFormat(
"<a style=\"cursor:text; TEXT-DECORATION: none;\">Publié par {0}</a>"
, userDisplayName);
sb.Append(
"</div>"
);
sb.Append(
"<div class=\"Exp-Comment-Date\">"
);
sb.Append(item[fieldCreated.Id].ToString());
sb.Append(
"</div>"
);
sb.Append(
"</div>"
);
sb.Append(
"<div class=\"Exp-Comment-Body\">"
);
sb.Append(item[fieldCommentBody.Id].ToString());
sb.Append(
"</div>"
);
sb.Append(
"</div>"
);
}
existingComments.Text = sb.ToString();
}
catch
{
//la liste n'existe pas
StringBuilder sb =
new
StringBuilder();
sb.Append(
"<div id=\"ExpComments\" class=\"Exp-Comments\">"
);
sb.Append(
"<div class=\"Exp-Comments-Number\"><span class=\"Exp-Comments-Number-Span\" >"
);
sb.AppendFormat(
"{0} commentaire "
,
"0"
);
sb.Append(
"</span></div>"
);
sb.Append(
"</div>"
);
existingComments.Text = sb.ToString();
}
}
}
});
}
protected
void
btSubmit_Click(
object
sender, EventArgs e)
{
try
{
SPSecurity.RunWithElevatedPrivileges(
delegate
()
{
using
(SPSite elevatedSite =
new
SPSite(SPContext.Current.Site.Url))
{
using
(SPWeb elevatedWeb = elevatedSite.OpenWeb(SPContext.Current.Web.ServerRelativeUrl))
{
if
(reComment.Content.Trim() !=
""
)
{
SPList commentList =
null
;
try
{
string
prefixUrl = elevatedWeb.ServerRelativeUrl ==
"/"
?
"/"
: elevatedWeb.ServerRelativeUrl +
"/"
;
commentList = elevatedWeb.GetList(prefixUrl + CommentListUrl);
}
catch
{
}
//if the comment list cannot be found we create it
if
(commentList ==
null
)
{
elevatedWeb.AllowUnsafeUpdates =
true
;
Guid newListId = elevatedWeb.Lists.Add(CommentListTitle,
""
, CommentListUrl, ExpertimePublishingCommentSiteFeatureId, 100,
""
, SPListTemplate.QuickLaunchOptions.Off);
commentList = elevatedWeb.Lists[newListId];
elevatedWeb.AllowUnsafeUpdates =
false
;
}
SPList list = commentList;
elevatedWeb.AllowUnsafeUpdates =
true
;
//creating the comment item
SPListItem newComment = list.Items.Add();
SPField fieldListItemId = list.Fields.GetFieldByInternalName(FieldName_ListItemId);
SPField fieldCommentBody = list.Fields.GetFieldByInternalName(FieldName_CommentBody);
SPField fieldCreatedBy = list.Fields.GetFieldByInternalName(
"Author"
);
newComment[fieldListItemId.Id] = SPContext.Current.ListItem.UniqueId.ToString();
newComment[fieldCommentBody.Id] = reComment.Content;
SPFieldUserValue val =
new
SPFieldUserValue(SPContext.Current.Web, SPContext.Current.Web.CurrentUser.ID, SPContext.Current.Web.CurrentUser.LoginName);
newComment[fieldCreatedBy.Id] = val;
newComment.SystemUpdate();
elevatedWeb.AllowUnsafeUpdates =
false
;
//updating the new comment in the display
StringBuilder sb =
new
StringBuilder();
sb.Append(
"<div class=\"Exp-Comment\">"
);
sb.Append(
"<div class=\"Exp-Comment-Header\">"
);
sb.Append(
"<div class=\"Exp-Comment-Author\">"
);
string
userDisplayName = SPContext.Current.Web.CurrentUser.Name;
string
userEmail = SPContext.Current.Web.CurrentUser.Email;
sb.AppendFormat(
"<a style=\"cursor:text; TEXT-DECORATION: none;\">{1}</a>"
, userEmail, userDisplayName);
sb.Append(
"</div>"
);
sb.Append(
"<div class=\"Exp-Comment-Date\">"
);
sb.Append(DateTime.Now.ToLongDateString());
sb.Append(
"</div>"
);
sb.Append(
"</div>"
);
sb.Append(
"<div class=\"Exp-Comment-Body\">"
);
sb.Append(reComment.Content);
sb.Append(
"</div>"
);
sb.Append(
"</div>"
);
newCommentLiteral.Text = sb.ToString();
reComment.Content =
string
.Empty;
btSubmit.Visible =
false
;
reComment.Visible =
false
;
btSubmit.Visible =
false
;
lblMessage.Visible =
false
;
}
}
}
});
}
catch
{
}
}
public
void
RegisterError(
string
message)
{
if
(
this
.Controls.Contains(_ErrorContainer))
{
//this way of generating a unique control id is used in some of the OOB web parts
int
uniqueCounter;
if
(HttpContext.Current.Items[
"GetUniqueControlId"
] !=
null
)
{
uniqueCounter = (
int
)HttpContext.Current.Items[
"GetUniqueControlId"
];
}
else
{
uniqueCounter = 0;
}
uniqueCounter++;
HttpContext.Current.Items[
"GetUniqueControlId"
] = uniqueCounter;
//create a custom validator to register the current error message with the ValidationSummary control
CustomValidator cv =
new
CustomValidator();
cv.ID =
string
.Concat(
"_Error_"
, uniqueCounter);
cv.ValidationGroup = _ValidationGroupId;
cv.Display = ValidatorDisplay.None;
cv.IsValid =
false
;
cv.ErrorMessage = message;
this
.Controls.Add(cv);
}
else
{
//if RegisterError is called before the CreateChildControls override in AjaxBasePart then transfer the user to an error page using the SPUtility
Microsoft.SharePoint.Utilities.SPUtility.TransferToErrorPage(
"The CreateChildControls function of the AjaxBasePart has not been called. You probably need to add \"base.CreateChildControls()\" to the top of your CreateChildControls override."
);
}
}
}
}
0

Renato
Top achievements
Rank 1
answered on 24 Jul 2013, 09:12 AM
There is one detail, the code behind is in another project... dont knnow if that can be a problem but the structure was already like this when I got it, I am sending a print screen. User control (Comments.ascx) Code Behind (Comments.cs)
0

Renato
Top achievements
Rank 1
answered on 25 Jul 2013, 09:35 AM
I created a new User Control with the Code Behind on the same project... I put the code inside OnInit inside the CreateChildControl and it still returns reComment.Content empty.
The code recognizes the RadEditor but not the content...
Would be really nice to have some support from Telerik! thanks
protected
override
void
OnInit(EventArgs e)
{
Page.Init +=
delegate
(
object
sender, EventArgs e_Init)
{
protected
override
void
CreateChildControls()
{
The code recognizes the RadEditor but not the content...
Would be really nice to have some support from Telerik! thanks
0
Hello Renato,
If the editor has no content initially and you enter something, the editor's property Content will be empty on the init event after a postback. I can assure you that this behavior is expected and normal for the RadEditor due to the ASP.NET page life-cycle nature. Nevertheless you could use the page load event, where the content is loaded from the view-state of the application.
Please follow the next explanation in case of more information needed:
Telerik
If the editor has no content initially and you enter something, the editor's property Content will be empty on the init event after a postback. I can assure you that this behavior is expected and normal for the RadEditor due to the ASP.NET page life-cycle nature. Nevertheless you could use the page load event, where the content is loaded from the view-state of the application.
Please follow the next explanation in case of more information needed:
- Page Init event: In this stage the RadEditor is initialized and cointains in the page as control but the view-state is not loaded, so the editor could not get the text for the content.
- Page Init Complete event: The view-state is loaded and ready for the controls to get the needed information from it.
- Page Load event: Here the Radeditor has the content loaded from the view-state, so that it can be set or get as reference.
You could also follow this MSDN help article for more information about the life-cycle events.
I am attaching a sample project using the mentioned three events, so that you could follow it and investigate the content value on each stage of the page.
While investigating this case I found other forum posts about the same issue. I would like to ask to open only one support thread about the same issue, so that we are able to track the information correctly and provide you with a proper solution.
Regards,
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
0

Renato
Top achievements
Rank 1
answered on 29 Jul 2013, 10:49 AM
Hi Ianko, I have a scenario that is unfortunatlly totally different than the example... I have a User Control that is being included in a page without code behind. I will post the 3 files: the page, the User Control and the User Control Code Behind so please let me know if it is possible to retrieve the Content of the RadEditor this way... Thanks!
PAGE
USER CONTROL
USER CONTROL CODE BEHIND
PAGE
<%@Page Language="C#" Inherits="Microsoft.SharePoint.Publishing.PublishingLayoutPage,Microsoft.SharePoint.Publishing,Version=15.0.0.0,Culture=neutral,PublicKeyToken=71e9bce111e9429c" meta:progid="SharePoint.WebPartPage.Document" %>
<%@Register TagPrefix="SharePointWebControls" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@Register TagPrefix="WebPartPages" Namespace="Microsoft.SharePoint.WebPartPages" Assembly="Microsoft.SharePoint, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@Register TagPrefix="OSRVWC" Namespace="Microsoft.Office.Server.WebControls" Assembly="Microsoft.Office.Server, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@Register TagPrefix="SPSWC" Namespace="Microsoft.SharePoint.Portal.WebControls" Assembly="Microsoft.SharePoint.Portal, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@Register TagPrefix="SEARCHWC" Namespace="Microsoft.Office.Server.Search.WebControls" Assembly="Microsoft.Office.Server.Search, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@Register TagPrefix="PublishingWebControls" Namespace="Microsoft.SharePoint.Publishing.WebControls" Assembly="Microsoft.SharePoint.Publishing, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@Register TagPrefix="WpNs0" Namespace="Expertime.TagCloud" Assembly="Expertime.TagCloud, Version=1.0.1.0, Culture=neutral, PublicKeyToken=449b57c561474408" %>
<%@Register TagPrefix="HighLightWebControls" Namespace="HighLight.WebControls" Assembly="HighLight, Version=1.0.0.0, Culture=neutral, PublicKeyToken=a020282aed59311d" %>
<%@Register TagPrefix="FTVControl" Namespace="FTV.Intranet.Controls" Assembly=" FTV.Intranet, Version=1.0.0.0, Culture=neutral, PublicKeyToken=d5091d74f74db7c5" %>
<%@Register TagPrefix="FTV" TagName="ActuTheme" Src="~/_controltemplates/15/FTV_ActuParTheme.ascx" %>
<%@Register TagPrefix="FTVActuTags" Namespace="Expertime.TagCloud" Assembly="Expertime.TagCloud, Version=1.0.1.0, Culture=neutral, PublicKeyToken=449b57c561474408" %>
<%@Register TagPrefix="FTVActuTag" Namespace="FTV.Intranet.Module_Actualites" Assembly=" FTV.Intranet, Version=1.0.0.0, Culture=neutral, PublicKeyToken=d5091d74f74db7c5" %>
<%@ Register Tagprefix="Taxonomy" Namespace="Microsoft.SharePoint.Taxonomy" Assembly="Microsoft.SharePoint.Taxonomy, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@Register TagPrefix="FTV" TagName="CheckNepasAlerter" Src="~/_controltemplates/15/FTV2013/ActusCheckDefaultValues.ascx" %>
<%@Register TagPrefix="SharePointPortalControls" Namespace="Microsoft.SharePoint.Portal.WebControls" Assembly="Microsoft.SharePoint.Portal, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@Register Src="~/_controltemplates/15/Comments.ascx" TagName="Comments" TagPrefix="Expertime" %>
<
asp:Content
ContentPlaceHolderId
=
"PlaceHolderAdditionalPageHead"
runat
=
"server"
>
<
SharePointWebControls:CssRegistration
ID
=
"FTVRibbonStyle"
name="<% $SPUrl:~sitecollection/_layouts/15/FTV.Intranet.Assets/css/FTV.RadeditorSP2013.css %>" runat="server"/>
</
asp:Content
>
<
asp:Content
ContentPlaceHolderId
=
"PlaceHolderTitleBreadcrumb"
runat
=
"server"
>
<
div
class
=
"breadcrumb"
>
<
asp:SiteMapPath
ID
=
"siteMapPath"
Runat
=
"server"
SiteMapProvider
=
"CurrentNavSiteMapProviderNoEncode"
RenderCurrentNodeAsLink
=
"true"
SkipLinkText
=
""
CurrentNodeStyle-CssClass
=
"breadcrumbCurrent"
NodeStyle-CssClass
=
"ms-sitemapdirectional"
/>
</
div
>
</
asp:Content
>
<
asp:Content
ContentPlaceholderID
=
"PlaceHolderMain"
runat
=
"server"
>
<
FTV:CheckNepasAlerter
runat
=
"server"
></
FTV:CheckNepasAlerter
>
<
script
language
=
"javascript"
type
=
"text/javascript"
src
=
"_layouts/15/FTV.Intranet/js/Expertime-Charactere.Counter.js"
></
script
>
<
FTVControl:FTV_ActuVisibility
ID
=
"FTV_ActuVisibility"
runat
=
"server"
/>
<
div
id
=
"ftv-central-middlecol"
>
<
div
class
=
"ftv-wp-title"
><
FTVControl:FTV_CurrentWeb
ID
=
"FTV_CurrentWeb2"
Type
=
"Actu - "
runat
=
"server"
></
FTVControl:FTV_CurrentWeb
></
div
>
<
span
class
=
"exp-actu-mel"
>
<
PublishingWebControls:EditModePanel
runat
=
"server"
id
=
"editmodepane2"
>
<
FTVControl:FTV_LoadDateControl
ID
=
"StartDateFieldControl"
FieldName
=
"Actus_startDate"
runat
=
"server"
/>
<
SharePointWebControls:DateTimeField
ID
=
"EndDateFieldControl"
FieldName
=
"Actus_endDate"
runat
=
"server"
/>
</
PublishingWebControls:EditModePanel
>
</
span
>
<
div
class
=
"ftv-entry ftv-actu-article"
>
<
div
class
=
"ftv-entry-date"
>
<
FTVControl:FTV_DateOnlyControl
ID
=
"DateTimeField1"
FieldName
=
"ArticleStartDate"
runat
=
"server"
></
FTVControl:FTV_DateOnlyControl
>
<
FTVControl:FTV_SurTitre
ID
=
"surTitre"
FieldName
=
"Actus_surtitre"
runat
=
"server"
></
FTVControl:FTV_SurTitre
>
</
div
>
<
div
class
=
"ftv-entry-title"
>
<
SharePointWebControls:TextField
ID
=
"TextField2"
FieldName
=
"Title"
runat
=
"server"
></
SharePointWebControls:TextField
>
</
div
>
<
div
class
=
"ftv-content-wrapper"
>
<
div
class
=
"ftv-entry-image"
>
<
PublishingWebControls:EditModePanel
runat
=
"server"
id
=
"EditModePanel2"
PageDisplayMode
=
"Display"
>
<
FTVControl:FTV_DivImage
runat
=
"server"
ID
=
"DivImage"
></
FTVControl:FTV_DivImage
>
</
PublishingWebControls:EditModePanel
>
</
div
>
<
div
class
=
"ftv-entry-content"
>
<
div
class
=
"ftv-entry-text"
>
<
SharePointWebControls:NoteField
ID
=
"NoteField1"
FieldName
=
"Comments"
runat
=
"server"
></
SharePointWebControls:NoteField
>
<
div
id
=
"compteurnotefield"
style
=
"display:block"
><
p
><
span
id
=
"idcaract"
>255 signes</
span
></
p
></
div
>
<
script
language
=
"javascript"
type
=
"text/javascript"
>
if (document.getElementById("ctl00_PlaceHolderMain_NoteField1_ctl00_TextField")) {
document.getElementById("compteurnotefield").style.display = "block";
setCompteurCaract("ctl00_PlaceHolderMain_NoteField1_ctl00_TextField", "idcaract", 255);
} else {
document.getElementById("compteurnotefield").style.display = "none";
}
</
script
>
</
div
>
</
div
>
<
div
class
=
"ftv-clear"
></
div
>
</
div
>
<
PublishingWebControls:RichHtmlField
ID
=
"RichHtmlField1"
FieldName
=
"PublishingPageContent"
runat
=
"server"
></
PublishingWebControls:RichHtmlField
>
</
div
>
<
PublishingWebControls:editmodepanel
runat
=
"server"
id
=
"Editmodepanel3"
PageDisplayMode
=
"Display"
>
<
FTVActuTag:ActuUnitaire_Tags
ID
=
"ActuUnitaire_Tags1"
runat
=
"server"
FieldName
=
"Taxo_Tags_News"
></
FTVActuTag:ActuUnitaire_Tags
>
<
div
class
=
"ftv-content-navlinks ftv-navlink-general"
>
<
a
id
=
"aAllActus"
href="<%$SPUrl:~Site/Pages/actualites-home.aspx%>" runat="server">Toutes les actus - <
FTVControl:FTV_CurrentWeb
ID
=
"FTV_CurrentWeb1"
All
=
"true"
runat
=
"server"
></
FTVControl:FTV_CurrentWeb
></
a
>
</
div
>
</
PublishingWebControls:editmodepanel
>
<
div
class
=
"ftv-grid"
>
<
div
class
=
"ftv-grid-line"
>
<
WebPartPages:WebPartZone
id
=
"MiddleZone1"
runat
=
"server"
title
=
"MiddleZone1"
><
ZoneTemplate
></
ZoneTemplate
></
WebPartPages:WebPartZone
>
</
div
>
<
div
class
=
"ftv-grid-line"
>
<
div
class
=
"ftv-grid-col"
>
<
WebPartPages:WebPartZone
id
=
"MiddleZone2"
runat
=
"server"
title
=
"MiddleZone2"
><
ZoneTemplate
></
ZoneTemplate
></
WebPartPages:WebPartZone
>
</
div
>
<
div
class
=
"ftv-grid-col"
>
<
WebPartPages:WebPartZone
id
=
"MiddleZone3"
runat
=
"server"
title
=
"MiddleZone3"
><
ZoneTemplate
></
ZoneTemplate
></
WebPartPages:WebPartZone
>
</
div
>
<
div
class
=
"ftv-clear"
></
div
>
</
div
>
<
div
class
=
"ftv-grid-line"
>
<
WebPartPages:WebPartZone
id
=
"MiddleZone4"
runat
=
"server"
title
=
"MiddleZone4"
><
ZoneTemplate
></
ZoneTemplate
></
WebPartPages:WebPartZone
>
</
div
>
</
div
>
<
div
class
=
"exp-actu-comment"
>
<
PublishingWebControls:editmodepanel
runat
=
"server"
id
=
"expertimeCommentsEditModePanel"
PageDisplayMode
=
"Display"
>
<
Expertime:Comments
runat
=
"server"
id
=
"Comments1"
></
Expertime:Comments
>
</
PublishingWebControls:editmodepanel
>
</
div
>
<
PublishingWebControls:EditModePanel
runat
=
"server"
id
=
"editmodepanel1"
>
<
SharePointWebControls:BooleanField
ID
=
"BooleanField1"
FieldName
=
"Actus_alerte"
runat
=
"server"
>
</
SharePointWebControls:BooleanField
>
<
SharePointWebControls:BooleanField
ID
=
"BooleanField2"
FieldName
=
"Actus_remontee"
runat
=
"server"
>
</
SharePointWebControls:BooleanField
>
<
FTVActuTag:FTV_TDI
ID
=
"Theme"
runat
=
"server"
ListTDI="<%$Resources:FTV.Intranet,actus_themesListTitle%>" FieldName="Actus_theme">
</
FTVActuTag:FTV_TDI
>
<
PublishingWebControls:RichImageField
ID
=
"RichImageField2"
FieldName
=
"PublishingRollupImage"
runat
=
"server"
>
</
PublishingWebControls:RichImageField
>
<
Taxonomy:TaxonomyFieldControl
FieldName
=
"Taxo_Tags_News"
ID
=
"Taxo_Tags_News"
runat
=
"server"
/>
</
PublishingWebControls:EditModePanel
>
</
div
>
<
div
id
=
"ftv-central-rightcol"
>
<
WebPartPages:WebPartZone
id
=
"RightZone2"
runat
=
"server"
title
=
"Zone 2"
><
ZoneTemplate
></
ZoneTemplate
></
WebPartPages:WebPartZone
>
<
div
class
=
"ftv-rightcol-wp-separator"
></
div
>
<
div
class
=
"ftv-rightcol-wp"
>
<
div
class
=
"exp-actu-summarylink"
>
<
FTVControl:FTV_Telecharger
ID
=
"FTV_Telecharger1"
runat
=
"server"
FieldName
=
"SummaryLinks"
></
FTVControl:FTV_Telecharger
>
</
div
>
</
div
>
<
div
class
=
"ftv-rightcol-wp-separator"
></
div
>
<
div
class
=
"ftv-rightcol-wp"
>
<
div
class
=
"ftv-wp-title-4 ftv-wp-title"
>Tags</
div
>
<
FTVActuTags:TagCloud
ID
=
"TagCloud1"
TagCssPrefix
=
"TagStyle"
Recursive
=
"true"
TagPageURL="<%$SPUrl:~Site/Pages/actualites-home.aspx%>" UseCss="True" TagColumnName="Taxo_Tags_News" runat="server"></
FTVActuTags:TagCloud
>
</
div
>
<
div
class
=
"ftv-rightcol-wp-separator"
></
div
>
<
div
class
=
"ftv-rightcol-wp"
>
<
FTVControl:FTV_ActuVideoFieldSummaryLinks
ID
=
"SummaryLinkFieldControl2"
FieldName
=
"SummaryLinks2"
runat
=
"server"
__designer:Preview="<div align="left" class="ms-formfieldcontainer"><
div
class="ms-formfieldlabelcontainer" nowrap="nowrap"><
span
class="ms-formfieldlabel" nowrap="nowrap">Liens de synthèse 2</
span
></
div
><
div
class="ms-formfieldvaluecontainer"><
div
class="exp-actu-media"><
h3
class="exp-actus-media-title">MEDIA</
h3
><
div
class="exp-actu-mediaSL"></
div
></
div
></
div
></
div
>"
__designer:Values="<
P
N
=
'ID'
ID
=
'1'
T
=
'SummaryLinkFieldControl2'
/><
P
N
=
'ItemFieldValue'
ID
=
'2'
Serial
=
'AAEAAAD/////AQAAAAAAAAAGAQAAADE8ZGl2PlZhbGV1ciBkdSBjaGFtcCBMaWVucyBkZSBzeW50aMOoc2XCoDIuPC9kaXY+Cw'
/><
P
N
=
'ListItemFieldValue'
R
=
'2'
/><
P
N
=
'Visible'
T
=
'True'
/><
P
N
=
'FieldName'
T
=
'SummaryLinks2'
/><
P
N
=
'ControlMode'
E
=
'1'
/><
P
N
=
'InDesign'
T
=
'False'
/><
P
N
=
'Page'
ID
=
'3'
/><
P
N
=
'TemplateControl'
R
=
'3'
/><
P
N
=
'AppRelativeTemplateSourceDirectory'
R
=
'-1'
/>">
</
FTVControl:FTV_ActuVideoFieldSummaryLinks
>
</
div
>
<
div
class
=
"ftv-rightcol-wp-separator"
></
div
>
<
div
class
=
"ftv-rightcol-wp"
>
<
div
class
=
"ftv-wp-title-4 ftv-wp-title"
>sur le même thème</
div
>
<
FTV:ActuTheme
runat
=
"server"
ID
=
"FTV_ActuParTheme1"
NbChar
=
"70"
XslFileName
=
"FTV_ActuParTheme.xslt"
></
FTV:ActuTheme
>
</
div
>
<
WebPartPages:WebPartZone
id
=
"RightZone"
runat
=
"server"
title
=
"Zone 1"
><
ZoneTemplate
></
ZoneTemplate
></
WebPartPages:WebPartZone
>
</
div
>
</
asp:Content
>
<
asp:Content
ContentPlaceholderID
=
"UnderLeftnavZone"
runat
=
"server"
>
<
WebPartPages:WebPartZone
id
=
"undernav"
runat
=
"server"
title
=
"Zone undernav"
><
ZoneTemplate
></
ZoneTemplate
></
WebPartPages:WebPartZone
>
</
asp:Content
>
USER CONTROL
<%@ Control Language="C#" Inherits="Expertime.PublishingComments.Library.Controls.Comments, Expertime.PublishingComments.Library, Version=1.0.0.0, Culture=neutral, PublicKeyToken=6b9c9c28502002f7" %>
<%@ Register TagPrefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls"
Assembly="Microsoft.SharePoint, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI, Version=2013.2.611.45, Culture=Neutral, PublicKeyToken=121fae78165ba3d4" %>
<%@Register TagPrefix="SharePointPortalControls" Namespace="Microsoft.SharePoint.Portal.WebControls" Assembly="Microsoft.SharePoint.Portal, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<
style
type
=
"text/css"
>
/* The following CSS needs to be copied to the page to produce textbox-like RadEditor */ .reWrapper_corner, .reWrapper_center {
display: none !important;
}
.reLeftVerticalSide, .reRightVerticalSide, .reToolZone, .reToolCell {
background: white !important;
}
.reContentCell {
border-width: 0 !important;
}
.RadEditor {
filter: chroma(color=c2dcf0);
}
</
style
>
<
telerik:RadCodeBlock
ID
=
"RadCodeBlock1"
runat
=
"server"
>
<
script
type
=
"text/javascript"
>
var currentLoadingPanel = null;
var btSubmit = null;
function RequestStart(sender, args) {
currentLoadingPanel = $find("<%= RadAjaxLoadingPanel1.ClientID%>");
btSubmit = "<%= panlcomments.ClientID %>";
//show the loading panel over the updated control
currentLoadingPanel.show(btSubmit);
}
function ResponseEnd() {
//hide the loading panel and clean up the global variables
currentLoadingPanel.hide(btSubmit);
//clear
btSubmit.SetHtml("");
currentLoadingPanel = null;
btSubmit = null;
}
</
script
>
</
telerik:RadCodeBlock
>
<
div
class
=
"ftv-wp-title"
>
<
asp:Literal
runat
=
"server"
ID
=
"HeaderTitle"
></
asp:Literal
>
</
div
>
<
telerik:RadAjaxManager
ID
=
"RadAjaxManager1"
runat
=
"server"
>
<
AjaxSettings
>
<
telerik:AjaxSetting
AjaxControlID
=
"btSubmit"
>
<
UpdatedControls
>
<
telerik:AjaxUpdatedControl
ControlID
=
"newCommentLiteral"
LoadingPanelID
=
"RadAjaxLoadingPanel1"
/>
<
telerik:AjaxUpdatedControl
ControlID
=
"panlcomments"
LoadingPanelID
=
"RadAjaxLoadingPanel1"
/>
</
UpdatedControls
>
</
telerik:AjaxSetting
>
</
AjaxSettings
>
<
ClientEvents
OnRequestStart
=
"RequestStart"
OnResponseEnd
=
"ResponseEnd"
/>
</
telerik:RadAjaxManager
>
<
telerik:RadAjaxLoadingPanel
ID
=
"RadAjaxLoadingPanel1"
runat
=
"server"
BackgroundPosition
=
"Center"
Skin
=
"Vista"
>
</
telerik:RadAjaxLoadingPanel
>
<
div
class
=
"ftv-content-social ftv-type2"
>
<
div
class
=
"ftv-comments"
>
<
a
class
=
"ftv-entry-comments"
><
asp:Label
runat
=
"server"
ID
=
"NbCommentsLbl"
/></
a
>
</
div
>
<
div
class
=
"ftv-notes"
>
<
a
>Note</
a
>
<
SharePointPortalControls:AverageRatingFieldControl
ID
=
"PageRatingControl"
FieldName
=
"AverageRating"
runat
=
"server"
/>
</
div
>
</
div
>
<
div
class
=
"Exp-Comments"
id
=
"ExpComments"
>
<
asp:Literal
ID
=
"existingComments"
runat
=
"server"
></
asp:Literal
>
</
div
>
<
asp:Literal
ID
=
"newCommentLiteral"
runat
=
"server"
></
asp:Literal
>
<!-- on masque le control pour les anonymes -->
<
asp:Panel
ID
=
"panlcomments"
runat
=
"server"
>
<
div
class
=
"exp-comment-message"
style
=
"display: none;"
>
<
asp:Label
Visible
=
"false"
ID
=
"lblMessage"
Text
=
"Messages :"
runat
=
"server"
></
asp:Label
></
div
>
<
div
class
=
"ftv-wp-title ftv-reagir"
>laissez un commentaire</
div
>
<
div
class
=
"ftv-reagir-comment"
>
<
telerik:RadEditor
ID
=
"reComment"
runat
=
"server"
EditModes
=
"Design"
ToolbarMode
=
"ShowOnFocus"
ToolsWidth
=
"170px"
Width
=
"412px"
Height
=
"72px"
>
<
Tools
>
<
telerik:EditorToolGroup
>
<
telerik:EditorTool
Name
=
"Bold"
/>
<
telerik:EditorTool
Name
=
"Italic"
/>
<
telerik:EditorTool
Name
=
"StrikeThrough"
/>
<
telerik:EditorTool
Name
=
"Underline"
/>
<
telerik:EditorTool
Name
=
"InsertUnorderedList"
/>
<
telerik:EditorTool
Name
=
"InsertOrderedList"
/>
</
telerik:EditorToolGroup
>
</
Tools
>
</
telerik:RadEditor
>
<
span
class
=
"exp-bout-comm"
>
<
asp:Button
ID
=
"btSubmit"
runat
=
"server"
Text
=
"Valider"
OnClick
=
"btSubmit_Click"
/></
span
>
<%--<
span
class
=
"exp-bout-comm"
><
asp:Button
ID
=
"btSubmit"
runat
=
"server"
Text
=
"Valider"
OnClick
=
"btSubmit_Click"
CssClass
=
"Exp-Comment-Submit"
/></
span
>--%>
</
div
>
</
asp:Panel
>
<
asp:Panel
ID
=
"pnelAnonyme"
runat
=
"server"
>
</
asp:Panel
>
USER CONTROL CODE BEHIND
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Publishing;
using System.Web.UI.WebControls;
using Telerik.Web.UI;
using System.Data;
using System.Web.UI;
namespace Expertime.PublishingComments.Library.Controls
{
public partial class Comments : System.Web.UI.UserControl
{
#region Controls
protected Button btSubmit;
protected RadEditor reComment;
protected Literal existingComments;
protected GridView gv1;
protected Literal newCommentLiteral;
protected Label lblMessage;
protected Panel panlcomments;
protected Panel pnelAnonyme;
private string _ValidationGroupId;
private ValidationSummary _ErrorContainer;
private ScriptManager _AjaxManager;
#endregion
#region vars & cons
const string CommentListUrl = "ExpertimePublishingComments", CommentListTitle = "Expertime Comments";
const string ExpertimePublishingCommentSiteFeatureId = "68af5cec-59a1-4105-97a7-3fb7b68fbf46";
const string FieldName_ListItemId = "ListItemId", FieldName_CommentBody = "CommentBody";
#endregion
#region properties
public ScriptManager AjaxManager
{
get { return _AjaxManager; }
set { _AjaxManager = value; }
}
#endregion
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
if (ScriptManager.GetCurrent(Page) == null)
{
ScriptManager sMgr = new ScriptManager();
Page.Form.Controls.AddAt(0, sMgr);
}
string formOnSubmitAtt = this.Page.Form.Attributes["onsubmit"];
try
{
if (!string.IsNullOrEmpty(formOnSubmitAtt) && formOnSubmitAtt == "return _spFormOnSubmitWrapper();")
{
Page.Form.Attributes["onsubmit"] = "_spFormOnSubmitWrapper();";
}
}
catch { }
try
{
if (btSubmit == null)
btSubmit = this.FindControl("btSubmit") as Button;
if (reComment == null)
reComment = this.FindControl("reComment") as RadEditor;
if (existingComments == null)
existingComments = this.FindControl("existingComments") as Literal;
if (gv1 == null)
gv1 = this.FindControl("gv1") as GridView;
if (newCommentLiteral == null)
newCommentLiteral = this.FindControl("newCommentLiteral") as Literal;
GetExistingComments();
}
catch (Exception exc)
{
existingComments.Text = string.Format("<
span
class=\"Exp-Error\">{0}</
span
>", exc.Message);
}
if (SPContext.Current.Web.CurrentUser == null)
{
panlcomments.Visible = false;
pnelAnonyme.Visible = true;
}
else
{
panlcomments.Visible = true;
pnelAnonyme.Visible = false;
}
}
//protected override void OnInit(EventArgs e)
//{
// Page.Init += delegate(object sender, EventArgs e_Init)
// {
// if (ScriptManager.GetCurrent(Page) == null)
// {
// ScriptManager sMgr = new ScriptManager();
// Page.Form.Controls.AddAt(0, sMgr);
// }
// string formOnSubmitAtt = this.Page.Form.Attributes["onsubmit"];
// try
// {
// if (!string.IsNullOrEmpty(formOnSubmitAtt) && formOnSubmitAtt == "return _spFormOnSubmitWrapper();")
// {
// Page.Form.Attributes["onsubmit"] = "_spFormOnSubmitWrapper();";
// }
// }
// catch { }
// try
// {
// if (btSubmit == null)
// btSubmit = this.FindControl("btSubmit") as Button;
// if (reComment == null)
// reComment = this.FindControl("reComment") as RadEditor;
// if (existingComments == null)
// existingComments = this.FindControl("existingComments") as Literal;
// if (gv1 == null)
// gv1 = this.FindControl("gv1") as GridView;
// if (newCommentLiteral == null)
// newCommentLiteral = this.FindControl("newCommentLiteral") as Literal;
// GetExistingComments();
// }
// catch (Exception exc)
// {
// existingComments.Text = string.Format("<
span
class=\"Exp-Error\">{0}</
span
>", exc.Message);
// }
// if (SPContext.Current.Web.CurrentUser == null)
// {
// panlcomments.Visible = false;
// pnelAnonyme.Visible = true;
// }
// else
// {
// panlcomments.Visible = true;
// pnelAnonyme.Visible = false;
// }
// };
// base.OnInit(e);
//}
protected override void CreateChildControls()
{
base.CreateChildControls();
if (!this.Controls.Contains(_ErrorContainer))
{
_ValidationGroupId = Guid.NewGuid().ToString();
_ErrorContainer = new ValidationSummary();
_ErrorContainer.ID = "_ErrorContainer";
_ErrorContainer.ValidationGroup = _ValidationGroupId;
_ErrorContainer.BorderStyle = BorderStyle.Solid;
_ErrorContainer.BorderWidth = Unit.Pixel(3);
_ErrorContainer.BorderColor = System.Drawing.Color.Red;
this.Controls.Add(_ErrorContainer);
}
Literal HeaderTitle = this.FindControl("HeaderTitle") as Literal;
if (HeaderTitle == null) throw new ArgumentNullException("le controle HeaderTitle n'existe pas");
if (HttpContext.Current.User.Identity.IsAuthenticated)
HeaderTitle.Text = "Réagir";
else
{
HeaderTitle.Text = "<
div
class
=
'ftv-wp-title ftv-title-separator'
>Réagir</
div
>" +
"<
div
class
=
'ftv-offline'
><
a
><
h6
>Connectez-vous</
h6
> pour réagir</
a
></
div
>";
}
}
private void GetExistingComments()
{
Guid siteId = SPContext.Current.Site.ID, webId = SPContext.Current.Web.ID;
SPSecurity.RunWithElevatedPrivileges(delegate()
{
using (SPSite elevatedSite = new SPSite(siteId))
{
using (SPWeb elevatedWeb = elevatedSite.OpenWeb(webId))
{
try
{
string prefixUrl = elevatedWeb.ServerRelativeUrl == "/" ? "/" : elevatedWeb.ServerRelativeUrl + "/";
SPList commentList = elevatedWeb.GetList(prefixUrl + CommentListUrl);
SPQuery query = new SPQuery();
string queryString = @"<
OrderBy
>
<
FieldRef
Name
=
""
Created""
Ascending
=
""
True"" />
</
OrderBy
>
<
Where
>
<
Eq
>
<
FieldRef
Name
=
""
ListItemId"" />
<
Value
Type
=
""
Text"">{0}</
Value
>
</
Eq
>
</
Where
>";
query.Query = string.Format(queryString, SPContext.Current.ListItem.UniqueId.ToString());
SPListItemCollection items = commentList.GetItems(query);
StringBuilder sb = new StringBuilder();
var NbCommentsLbl = this.FindControl("NbCommentsLbl") as Label;
if (NbCommentsLbl == null) throw new ArgumentNullException("le controle NbCommentsLbl n'existe pas");
if (items.Count <= 1)
NbCommentsLbl.Text = String.Format("{0} commentaire", items.Count.ToString());
else
NbCommentsLbl.Text = String.Format("{0} commentaires", items.Count.ToString());
// SPField fieldListItemId = commentList.Fields.GetFieldByInternalName(FieldName_ListItemId);
SPField fieldCommentBody = commentList.Fields.GetFieldByInternalName(FieldName_CommentBody);
SPField fieldCreatedBy = commentList.Fields.GetFieldByInternalName("Author");
SPField fieldCreated = commentList.Fields.GetFieldByInternalName("Created");
foreach (SPListItem item in items)
{
sb.Append("<
div
class=\"Exp-Comment\">");
sb.Append("<
div
class=\"Exp-Comment-Header\">");
sb.Append("<
div
class=\"Exp-Comment-Author\">");
SPFieldUserValue fieldValue = fieldCreatedBy.GetFieldValue(item[fieldCreatedBy.Id].ToString()) as SPFieldUserValue;
string userDisplayName = fieldValue.User.Name;
sb.AppendFormat("<
a
style=\"cursor:text; TEXT-DECORATION: none;\">Publié par {0}</
a
>", userDisplayName);
sb.Append("</
div
>");
sb.Append("<
div
class=\"Exp-Comment-Date\">");
sb.Append(item[fieldCreated.Id].ToString());
sb.Append("</
div
>");
sb.Append("</
div
>");
sb.Append("<
div
class=\"Exp-Comment-Body\">");
sb.Append(item[fieldCommentBody.Id].ToString());
sb.Append("</
div
>");
sb.Append("</
div
>");
}
existingComments.Text = sb.ToString();
}
catch
{
//la liste n'existe pas
StringBuilder sb = new StringBuilder();
sb.Append("<
div
id=\"ExpComments\" class=\"Exp-Comments\">");
sb.Append("<
div
class=\"Exp-Comments-Number\"><
span
class=\"Exp-Comments-Number-Span\" >");
sb.AppendFormat("{0} commentaire ", "0");
sb.Append("</
span
></
div
>");
sb.Append("</
div
>");
existingComments.Text = sb.ToString();
}
}
}
});
}
protected void btSubmit_Click(object sender, EventArgs e)
{
try
{
SPSecurity.RunWithElevatedPrivileges(delegate()
{
using (SPSite elevatedSite = new SPSite(SPContext.Current.Site.Url))
{
using (SPWeb elevatedWeb = elevatedSite.OpenWeb(SPContext.Current.Web.ServerRelativeUrl))
{
if (reComment.Content.Trim() != "")
{
SPList commentList = null;
try
{
string prefixUrl = elevatedWeb.ServerRelativeUrl == "/" ? "/" : elevatedWeb.ServerRelativeUrl + "/";
commentList = elevatedWeb.GetList(prefixUrl + CommentListUrl);
}
catch
{
}
//if the comment list cannot be found we create it
if (commentList == null)
{
elevatedWeb.AllowUnsafeUpdates = true;
Guid newListId = elevatedWeb.Lists.Add(CommentListTitle, "", CommentListUrl, ExpertimePublishingCommentSiteFeatureId, 100, "", SPListTemplate.QuickLaunchOptions.Off);
commentList = elevatedWeb.Lists[newListId];
elevatedWeb.AllowUnsafeUpdates = false;
}
SPList list = commentList;
elevatedWeb.AllowUnsafeUpdates = true;
//creating the comment item
SPListItem newComment = list.Items.Add();
SPField fieldListItemId = list.Fields.GetFieldByInternalName(FieldName_ListItemId);
SPField fieldCommentBody = list.Fields.GetFieldByInternalName(FieldName_CommentBody);
SPField fieldCreatedBy = list.Fields.GetFieldByInternalName("Author");
newComment[fieldListItemId.Id] = SPContext.Current.ListItem.UniqueId.ToString();
newComment[fieldCommentBody.Id] = reComment.Content;
SPFieldUserValue val = new SPFieldUserValue(SPContext.Current.Web, SPContext.Current.Web.CurrentUser.ID, SPContext.Current.Web.CurrentUser.LoginName);
newComment[fieldCreatedBy.Id] = val;
newComment.SystemUpdate();
elevatedWeb.AllowUnsafeUpdates = false;
//updating the new comment in the display
StringBuilder sb = new StringBuilder();
sb.Append("<
div
class=\"Exp-Comment\">");
sb.Append("<
div
class=\"Exp-Comment-Header\">");
sb.Append("<
div
class=\"Exp-Comment-Author\">");
string userDisplayName = SPContext.Current.Web.CurrentUser.Name;
string userEmail = SPContext.Current.Web.CurrentUser.Email;
sb.AppendFormat("<
a
style=\"cursor:text; TEXT-DECORATION: none;\">{1}</
a
>", userEmail, userDisplayName);
sb.Append("</
div
>");
sb.Append("<
div
class=\"Exp-Comment-Date\">");
sb.Append(DateTime.Now.ToLongDateString());
sb.Append("</
div
>");
sb.Append("</
div
>");
sb.Append("<
div
class=\"Exp-Comment-Body\">");
sb.Append(reComment.Content);
sb.Append("</
div
>");
sb.Append("</
div
>");
newCommentLiteral.Text = sb.ToString();
reComment.Content = string.Empty;
btSubmit.Visible = false;
reComment.Visible = false;
btSubmit.Visible = false;
lblMessage.Visible = false;
}
}
}
});
}
catch
{
}
}
public void RegisterError(string message)
{
if (this.Controls.Contains(_ErrorContainer))
{
//this way of generating a unique control id is used in some of the OOB web parts
int uniqueCounter;
if (HttpContext.Current.Items["GetUniqueControlId"] != null)
{
uniqueCounter = (int)HttpContext.Current.Items["GetUniqueControlId"];
}
else
{
uniqueCounter = 0;
}
uniqueCounter++;
HttpContext.Current.Items["GetUniqueControlId"] = uniqueCounter;
//create a custom validator to register the current error message with the ValidationSummary control
CustomValidator cv = new CustomValidator();
cv.ID = string.Concat("_Error_", uniqueCounter);
cv.ValidationGroup = _ValidationGroupId;
cv.Display = ValidatorDisplay.None;
cv.IsValid = false;
cv.ErrorMessage = message;
this.Controls.Add(cv);
}
else
{
//if RegisterError is called before the CreateChildControls override in AjaxBasePart then transfer the user to an error page using the SPUtility
Microsoft.SharePoint.Utilities.SPUtility.TransferToErrorPage("The CreateChildControls function of the AjaxBasePart has not been called. You probably need to add \"base.CreateChildControls()\" to the top of your CreateChildControls override.");
}
}
}
}
0

Renato
Top achievements
Rank 1
answered on 30 Jul 2013, 08:11 AM
I noticed that on that line <ClientEvents OnRequestStart="RequestStart" OnResponseEnd="ResponseEnd" />
the ResponseEnd clears the value of the RadEditor, is it possible not to clear the value? Could it be the reason why I cant access the value of the RadEditor in my code behind? pls I need an answer, it's been more than a week that I cant find a solution for this or answers to solve my Telerik problem... Thanks!
the ResponseEnd clears the value of the RadEditor, is it possible not to clear the value? Could it be the reason why I cant access the value of the RadEditor in my code behind? pls I need an answer, it's been more than a week that I cant find a solution for this or answers to solve my Telerik problem... Thanks!
0
Hello Renato,
The mentioned client-side scripts does not implement functionality for clearing the editor's content. They are for showing and hiding the Ajax Loading Panel.
About the reference of the RadEditor in the Code-behind - yes with this setup you could get the editor and it's content. You could follow this setup I have been testing with as well as the sample project that uses it, which is attached to the post:
User control:
Code-behind:
If you still encounter the described problem you could implement a Client-side script that modifies the editor's content on it's load event. For more information you could follow this articles:
- Getting familiar with Client-Side API;
- Getting a Reference to RadEditor;
- OnClientLoad;
- get_html;
Regards,
Ianko
Telerik
The mentioned client-side scripts does not implement functionality for clearing the editor's content. They are for showing and hiding the Ajax Loading Panel.
About the reference of the RadEditor in the Code-behind - yes with this setup you could get the editor and it's content. You could follow this setup I have been testing with as well as the sample project that uses it, which is attached to the post:
User control:
<%@ Assembly Name="$SharePoint.Project.AssemblyFullName$" %>
<%@ Assembly Name="Microsoft.Web.CommandUI, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register Tagprefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register Tagprefix="Utilities" Namespace="Microsoft.SharePoint.Utilities" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register Tagprefix="asp" Namespace="System.Web.UI" Assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" %>
<%@ Import Namespace="Microsoft.SharePoint" %>
<%@ Register Tagprefix="WebPartPages" Namespace="Microsoft.SharePoint.WebPartPages" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="VisualWebPart1UserControl.ascx.cs" Inherits="VisualWebPartProject1.VisualWebPart1.VisualWebPart1UserControl" %>
<%@ Register Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI, Version=2013.2.611.35, Culture=neutral, PublicKeyToken=121fae78165ba3d4" TagPrefix="telerik"%>
<
telerik:RadEditor
ID
=
"reComment"
runat
=
"server"
></
telerik:RadEditor
>
<
asp:Button
ID
=
"Button1"
runat
=
"server"
text
=
"PostBack"
/>
Code-behind:
protected
override
void
OnLoad(EventArgs e)
{
base
.OnLoad(e);
if
(ScriptManager.GetCurrent(Page) ==
null
)
{
ScriptManager sMgr =
new
ScriptManager();
Page.Form.Controls.AddAt(0, sMgr);
}
if
(reComment ==
null
)
{
reComment =
this
.FindControl(
"reComment"
)
as
RadEditor;
}
string
content = reComment.Content;
reComment.Content =
"Some text "
+ content;
}
If you still encounter the described problem you could implement a Client-side script that modifies the editor's content on it's load event. For more information you could follow this articles:
- Getting familiar with Client-Side API;
- Getting a Reference to RadEditor;
- OnClientLoad;
- get_html;
Regards,
Ianko
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.