Create a string type property in webpart or toolpart cs file
private string _emailBody;
[Personalizable(true)]
[WebBrowsable(true)]
[WebDisplayName("Email Body")]
[WebDescription("Email body")]
public string EmailBody
{
get { return _emailBody; }
set
{
_emailBody = value.Replace("\r\n", "<br />").Replace("\r", "<br />").Replace("\n", "<br />");
}
}
it's normal textbox in sharepoint webpart property panel
let's change this textbox to textarea
jQuery.input2TextArea.js
(function ($) {
$.fn.input2Textarea = function () {
var me = $(this);
if(me.length == 0) return;
me.hide();
$("<textarea style='width:400px;height:280px;' name='" + me.attr("name") + "' id='" + me.attr("id") + "'>" + me.val().replace(/<br \/>/g,'\r\n') + "</textarea>").insertAfter(me);
me.remove();
me = null;
}
})(jQuery);
call this function in WebPart Ascx code, and you can get the input textbox name property from html source of the page the webpart is placed, here is ending with 'EmailBody_EDITOR'
$(document).ready(function () {
var mailbody = $("input[name$='$EmailBody_EDITOR']");
mailbody.length > 0 && mailbody.input2Textarea() && (mailbody = null);
});you'll see the input textbox turn to textarea when you midify the webpart.
本文介绍如何将SharePoint WebPart中的普通文本框转换为Textarea,通过使用jQuery插件实现这一变化,并提供了一段JavaScript代码来完成转换。

820

被折叠的 条评论
为什么被折叠?



