为Cs2.0发帖时添加[原创]等前缀
论坛里有人要求(http://online.whpu.edu.cn/Forums) 于是给论坛加了个前缀
代码如下:
原理很简单,就不详述了
using CommunityServer.Components;
using CommunityServer.Discussions.Components;
namespace Edot.CSAddOns.Controls
{
public class PostPrefixList : HtmlSelect
{
TextBox textToPrefix;
/// <summary>
/// 需要绑定的控件
/// </summary>
private String _controlToPrefix = null;
public String ControlToPrefix
{
get { return _controlToPrefix; }
set { _controlToPrefix = value; }
}
protected override void OnInit(EventArgs e)
{
this.Items.Add("请选择");
this.Items.Add("【原创】");
this.Items.Add("【转贴】");
this.Items.Add("【求助】");
this.Items.Add("【公告】");
this.Items.Add("【分享】");
this.Items.Add("【讨论】");
this.Items.Add("【推荐】");
this.Items.Add("【注意】");
this.Items.Add("【灌水】");
this.Items.Add("【已解决】");
base.OnInit(e);
}
protected override void OnPreRender(EventArgs e)
{
Page.RegisterClientScriptBlock("AddPrefixForForumPost", GetPrefixScript());
base.OnPreRender(e);
}
protected override void Render(HtmlTextWriter writer)
{
this.Attributes.Add("onchange", "AddPrefix()");
base.Render(writer);
}
private string GetPrefixScript()
{
if (_controlToPrefix == null)
return null;
textToPrefix = (TextBox)FindControl(_controlToPrefix);
string clientId = textToPrefix.ClientID;
string selectedText = " document.getElementById(\"{0}\").options[document.getElementById(\"{0}\").selectedIndex].text;";
StringBuilder sb = new StringBuilder();
sb.Append("<script language=\"javascript\">");
sb.AppendLine("function AddPrefix(){");
// 添加内容
sb.AppendLine("document.getElementById(\"" + clientId + "\").value += " + String.Format(selectedText, this.ClientID) + ";");
sb.AppendLine("}");
sb.AppendLine("</script>");
return sb.ToString();
}
}
}
using CommunityServer.Discussions.Components;
namespace Edot.CSAddOns.Controls
{
public class PostPrefixList : HtmlSelect
{
TextBox textToPrefix;
/// <summary>
/// 需要绑定的控件
/// </summary>
private String _controlToPrefix = null;
public String ControlToPrefix
{
get { return _controlToPrefix; }
set { _controlToPrefix = value; }
}
protected override void OnInit(EventArgs e)
{
this.Items.Add("请选择");
this.Items.Add("【原创】");
this.Items.Add("【转贴】");
this.Items.Add("【求助】");
this.Items.Add("【公告】");
this.Items.Add("【分享】");
this.Items.Add("【讨论】");
this.Items.Add("【推荐】");
this.Items.Add("【注意】");
this.Items.Add("【灌水】");
this.Items.Add("【已解决】");
base.OnInit(e);
}
protected override void OnPreRender(EventArgs e)
{
Page.RegisterClientScriptBlock("AddPrefixForForumPost", GetPrefixScript());
base.OnPreRender(e);
}
protected override void Render(HtmlTextWriter writer)
{
this.Attributes.Add("onchange", "AddPrefix()");
base.Render(writer);
}
private string GetPrefixScript()
{
if (_controlToPrefix == null)
return null;
textToPrefix = (TextBox)FindControl(_controlToPrefix);
string clientId = textToPrefix.ClientID;
string selectedText = " document.getElementById(\"{0}\").options[document.getElementById(\"{0}\").selectedIndex].text;";
StringBuilder sb = new StringBuilder();
sb.Append("<script language=\"javascript\">");
sb.AppendLine("function AddPrefix(){");
// 添加内容
sb.AppendLine("document.getElementById(\"" + clientId + "\").value += " + String.Format(selectedText, this.ClientID) + ";");
sb.AppendLine("}");
sb.AppendLine("</script>");
return sb.ToString();
}
}
}