实现表情插入的问题

kres520 2008-07-11 04:28:20
问题是:
有80张图片作为表情,图片分别为1.gif~80.gif
目的是点下“显示图片”按钮,显示出表情图片的列表(这个列表我写在了一个PANEL中),并且每点击一个表情,在下面的TEXTBOX中显示出[表情代号],如点击1.gif则在textbox中显示[1]。
为了点击一个图片不刷新网页,所以将所有表情和“显示图片”按钮写在了UPDATEPANEL中。代码如下
<asp:UpdatePanel ID="UpdatePanel1" runat="server" >
<ContentTemplate>
<asp:ImageButton ID="Imgbtn" runat="server" ImageUrl="/image/显示图片.jpg" onclick="Show"/>
<asp:Panel ID="pData" runat="server" BackColor=Black>

<asp:ImageButton ID="ImageButton1" runat="server" ImageUrl="image/face/1.gif" OnClick="Face1"/>
<asp:ImageButton ID="ImageButton2" runat="server" ImageUrl="image/face/2.gif"/>
<asp:ImageButton ID="ImageButton3" runat="server" ImageUrl="image/face/3.gif"/>
<asp:ImageButton ID="ImageButton4" runat="server" ImageUrl="image/face/4.gif"/>
........
</asp:Panel>
</ContentTemplate>
</asp:UpdatePanel>
Face1的代码是
protected void Face1(object sender, EventArgs e)
{
TextBox2.Text = TextBox2.Text + "[1]";
}
但是我点击图片1的时候TEXTBOX2中没有任何变化,是否与UPDATEPANEL有关?
另外请达人帮忙简化代码。。。这样枚举实在太麻烦了,不胜感激
...全文
235 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
kres520 2008-07-11
  • 打赏
  • 举报
回复
NB~准备收分,终于等到强银出现。。。不得不由衷的赞一下
蝶恋花雨 2008-07-11
  • 打赏
  • 举报
回复
蝶恋花雨 2008-07-11
  • 打赏
  • 举报
回复
读取数据
   protected void rpComment_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType != ListItemType.Header && e.Item.ItemType != ListItemType.Footer)
{
Literal ltContetn = e.Item.FindControl("ltContent") as Literal;
HiddenField HFcontent = e.Item.FindControl("HFcontent") as HiddenField;
string content = HFcontent.Value;
string[] face = { "[:-)]","[:-D]","[;-)]","[8-)]","[(6)]","[:-$]","[8o|]","[:-(]","[:-@]","[:-|]",
"[(&)]","[&-|]","[:-#]","[$-)]","[:-P]","[(@)]","[:'(]","[|-)]","[:-Z]","[:-S]",
"[*-(]","[:-%]","[^-)]","[:-*]","[(R)]","[(W)]","[(%)]","[(S)]","[(*)]","[(M)]",
"[(so)]","[(I)]","[(F)]","[(L)]","[(U)]","[(=)]","[(#)]","[(O)]","[(D)]","[(T)]" };
string[] faceImg = {"../../face/01.gif", "../../face/02.gif","../../face/03.gif", "../../face/04.gif",
"../../face/05.gif", "../../face/06.gif","../../face/07.gif", "../../face/08.gif",
"../../face/09.gif", "../../face/10.gif","../../face/11.gif", "../../face/12.gif",
"../../face/13.gif", "../../face/14.gif","../../face/15.gif", "../../face/16.gif",
"../../face/17.gif", "../../face/18.gif","../../face/19.gif", "../../face/20.gif",
"../../face/21.gif", "../../face/22.gif","../../face/23.gif", "../../face/24.gif",
"../../face/25.gif", "../../face/26.gif","../../face/27.gif", "../../face/28.gif",
"../../face/29.gif", "../../face/30.gif","../../face/31.gif", "../../face/32.gif",
"../../face/33.gif", "../../face/34.gif","../../face/35.gif", "../../face/36.gif",
"../../face/37.gif", "../../face/38.gif","../../face/39.gif", "../../face/40.gif"};
for (int i = 0; i < face.Length; i++)
{
content = content.Replace(face[i], "<img src='" + faceImg[i] + "' border='0'/> ");
}
ltContetn.Text += content.ToString();
}
}
蝶恋花雨 2008-07-11
  • 打赏
  • 举报
回复
 DisplayEmotions("EmotionsDiv", "NoHtmlCommentContent");

function DisplayEmotions(container, editor)
{
var em = "<img src='../../face/01.gif' alt=\"微笑 [:-)]\" onclick=\"AddEmotion('{editor}','[:-)]')\" border=\"0\" class=\"editorEmotion\"/> <img src='../../face/02.gif' alt=\"大笑 [:-D]\" onclick=\"AddEmotion('{editor}','[:-D]')\" border=\"0\" class=\"editorEmotion\"/> <img src='../../face/03.gif' alt=\"眨眼 [;-)]\" onclick=\"AddEmotion('{editor}','[;-)]')\" border=\"0\" class=\"editorEmotion\"/> <img src='../../face/04.gif' alt=\"装酷 [8-)]\" onclick=\"AddEmotion('{editor}','[8-)]')\" border=\"0\" class=\"editorEmotion\"/> <img src='../../face/05.gif' alt=\"独眼龙 [(6)]\" onclick=\"AddEmotion('{editor}','[(6)]')\" border=\"0\" class=\"editorEmotion\"/> <img src='../../face/06.gif' alt=\"害羞 [:-$]\" onclick=\"AddEmotion('{editor}','[:-$]')\" border=\"0\" class=\"editorEmotion\"/> <img src='../../face/07.gif' alt=\"生气 [8o|]\" onclick=\"AddEmotion('{editor}','[8o|]')\" border=\"0\" class=\"editorEmotion\"/> <img src='../../face/08.gif' alt=\"发呆 [:-(]\" onclick=\"AddEmotion('{editor}','[:-(]')\" border=\"0\" class=\"editorEmotion\"/> <img src='../../face/09.gif' alt=\"发怒 [:-@]\" onclick=\"AddEmotion('{editor}','[:-@]')\" border=\"0\" class=\"editorEmotion\"/> <img src='../../face/10.gif' alt=\"惊讶 [:-|]\" onclick=\"AddEmotion('{editor}','[:-|]')\" border=\"0\" class=\"editorEmotion\"/> <img src='../../face/11.gif' alt=\"猫猫 [(&)]\" onclick=\"AddEmotion('{editor}','[(&)]')\" border=\"0\" class=\"editorEmotion\"/> <img src='../../face/12.gif' alt=\"白眼 [&-|]\" onclick=\"AddEmotion('{editor}','[&-|]')\" border=\"0\" class=\"editorEmotion\"/> <img src='../../face/13.gif' alt=\"不说 [:-#]\" onclick=\"AddEmotion('{editor}','[:-#]')\" border=\"0\" class=\"editorEmotion\"/> <img src='../../face/14.gif' alt=\"眼馋 [$-)]\" onclick=\"AddEmotion('{editor}','[$-)]')\" border=\"0\" class=\"editorEmotion\"/> <img src='../../face/15.gif' alt=\"吐舌头 [:-P]\" onclick=\"AddEmotion('{editor}','[:-P]')\" border=\"0\" class=\"editorEmotion\"/> <img src='../../face/16.gif' alt=\"猫咪 [(@)]\" onclick=\"AddEmotion('{editor}','[(@)]')\" border=\"0\" class=\"editorEmotion\"/> <img src='../../face/17.gif' alt=\"大哭 [:'(]\" onclick=\"AddEmotion('{editor}','[:\\\'(]')\" border=\"0\" class=\"editorEmotion\"/> <img src='../../face/18.gif' alt=\"低头 [|-)]\" onclick=\"AddEmotion('{editor}','[|-)]')\" border=\"0\" class=\"editorEmotion\"/> <img src='../../face/19.gif' alt=\"困了 [:-Z]\" onclick=\"AddEmotion('{editor}','[:-Z]')\" border=\"0\" class=\"editorEmotion\"/> <img src='../../face/20.gif' alt=\"困惑 [:-S]\" onclick=\"AddEmotion('{editor}','[:-S]')\" border=\"0\" class=\"editorEmotion\"/> <img src='../../face/21.gif' alt=\"悲伤 [*-(]\" onclick=\"AddEmotion('{editor}','[*-(]')\" border=\"0\" class=\"editorEmotion\"/> <img src='../../face/22.gif' alt=\"狂吐 [:-%]\" onclick=\"AddEmotion('{editor}','[:-%]')\" border=\"0\" class=\"editorEmotion\"/> <img src='../../face/23.gif' alt=\"伤心 [^-)]\" onclick=\"AddEmotion('{editor}','[^-)]')\" border=\"0\" class=\"editorEmotion\"/> <img src='../../face/24.gif' alt=\"汗 [:-*]\" onclick=\"AddEmotion('{editor}','[:-*]')\" border=\"0\" class=\"editorEmotion\"/> <img src='../../face/25.gif' alt=\"花 [(R)]\" onclick=\"AddEmotion('{editor}','[(R)]')\" border=\"0\" class=\"editorEmotion\"/> <img src='../../face/26.gif' alt=\"花 [(W)]\" onclick=\"AddEmotion('{editor}','[(W)]')\" border=\"0\" class=\"editorEmotion\"/> <img src='../../face/27.gif' alt=\"太阳 [(%)]\" onclick=\"AddEmotion('{editor}','[(%)]')\" border=\"0\" class=\"editorEmotion\"/> <img src='../../face/28.gif' alt=\"月亮 [(S)]\" onclick=\"AddEmotion('{editor}','[(S)]')\" border=\"0\" class=\"editorEmotion\"/> <img src='../../face/29.gif' alt=\"星星 [(*)]\" onclick=\"AddEmotion('{editor}','[(*)]')\" border=\"0\" class=\"editorEmotion\"/> <img src='../../face/30.gif' alt=\"邮件 [(M)]\" onclick=\"AddEmotion('{editor}','[(M)]')\" border=\"0\" class=\"editorEmotion\"/> <img src='../../face/31.gif' alt=\"足球 [(so)]\" onclick=\"AddEmotion('{editor}','[(so)]')\" border=\"0\" class=\"editorEmotion\"/> <img src='../../face/32.gif' alt=\"亮亮 [(I)]\" onclick=\"AddEmotion('{editor}','[(I)]')\" border=\"0\" class=\"editorEmotion\"/> <img src='../../face/33.gif' alt=\"咖啡 [(F)]\" onclick=\"AddEmotion('{editor}','[(F)]')\" border=\"0\" class=\"editorEmotion\"/> <img src='../../face/34.gif' alt=\"心 [(L)]\" onclick=\"AddEmotion('{editor}','[(L)]')\" border=\"0\" class=\"editorEmotion\"/> <img src='../../face/35.gif' alt=\"心 [(U)]\" onclick=\"AddEmotion('{editor}','[(U)]')\" border=\"0\" class=\"editorEmotion\"/> <img src='../../face/36.gif' alt=\"便便 [(=)]\" onclick=\"AddEmotion('{editor}','[(=)]')\" border=\"0\" class=\"editorEmotion\"/> <img src='../../face/37.gif' alt=\"电视 [(#)]\" onclick=\"AddEmotion('{editor}','[(#)]')\" border=\"0\" class=\"editorEmotion\"/> <img src='../../face/38.gif' alt=\"时间 [(O)]\" onclick=\"AddEmotion('{editor}','[(O)]')\" border=\"0\" class=\"editorEmotion\"/> <img src='../../face/39.gif' alt=\"酒 [(D)]\" onclick=\"AddEmotion('{editor}','[(D)]')\" border=\"0\" class=\"editorEmotion\"/> <img src='../../face/40.gif' alt=\"电话 [(T)]\" onclick=\"AddEmotion('{editor}','[(T)]')\" border=\"0\" class=\"editorEmotion\"/> ";
if (em != "")
{
em = em.replace(new RegExp("{editor}","gm"), editor);
}
if(document.getElementById(container))
{
document.getElementById(container).innerHTML = em;
}
}
function AddEmotion(editor, emotion)
{
var edt = document.getElementById(editor);
if(edt)
{
if (edt.value == "字数上限为2000字")
{
edt.value = "";
}
edt.value += emotion;
}
}

<asp:TextBox TextMode="MultiLine" runat="server" Width="100%" name="NoHtmlCommentContent" id="NoHtmlCommentContent" rows="8" cols="80" onFocus="if(this.value=='字数上限为2000字'){this.value='';}this.select();">字数上限为2000字</asp:TextBox>
	<div id="EmotionsDiv" style="width:200px;font-family:verdana;font-size:12px;" align="left">
<img alt="微笑 [:-)]" border="0" class="editorEmotion"
onclick="AddEmotion('NoHtmlCommentContent','[:-)]')"
src="../../face/01.gif" /> <img
alt="大笑 [:-D]" border="0" class="editorEmotion"
onclick="AddEmotion('NoHtmlCommentContent','[:-D]')"
src="../../face/02.gif" /> <img
alt="眨眼 [;-)]" border="0" class="editorEmotion"
onclick="AddEmotion('NoHtmlCommentContent','[;-)]')"
src="../../face/03.gif" /> <img
alt="装酷 [8-)]" border="0" class="editorEmotion"
onclick="AddEmotion('NoHtmlCommentContent','[8-)]')"
src="../../face/04.gif" /> <img
alt="独眼龙 [(6)]" border="0" class="editorEmotion"
onclick="AddEmotion('NoHtmlCommentContent','[(6)]')"
src="../../face/05.gif" /> <img
alt="发呆 [:-(]" border="0" class="editorEmotion"
onclick="AddEmotion('NoHtmlCommentContent','[:-(]')"
src="../../face/08.gif" /> <br /></div>

参考下
lass_name 2008-07-11
  • 打赏
  • 举报
回复
up
keyake863 2008-07-11
  • 打赏
  • 举报
回复
这个还要用 UPDATEPANEL?
楼主过于依赖这些控件了,这个用javascript完全能实现。
sheng9hhd 2008-07-11
  • 打赏
  • 举报
回复
一般使用js+iframe实现
烈火焚身 2008-07-11
  • 打赏
  • 举报
回复

关注 + 帮顶
Magic_YJL 2008-07-11
  • 打赏
  • 举报
回复
关注 + 帮顶
kres520 2008-07-11
  • 打赏
  • 举报
回复
对了,还有就是能不能在TEXTBOX的光标处插入代码,而不是TextBox2.Text = TextBox2.Text + "[1]"; 这样在最后插入

62,133

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧