本文介绍了点击按钮隐藏共享图标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我在更新面板中有一个表,其中我显示了来自数据库的一些数据,一些图像按钮和一些共享图标(删除了垃圾链接)。当我的页面加载时,它会显示所有信息,按钮和共享图标,但是当我点击按钮时,共享图标会隐藏。当我刷新页面然后它再次显示。单击按钮时隐藏的原因。 < asp:UpdatePanel ID = UpdatePanel1 runat = 服务器 UpdateMode = 条件 > < ContentTemplate > < table > < tr > < td colspan = 5 > < asp:ImageButton ID = btn_like runat = server 工具提示 = 例如 onclick = btn_like_Click1 OnClientClick = 显示('shareicons'); / > < asp:ImageButton ID = btn_favorite runat = server 工具提示 = 收藏夹 onclick = btn_favorite_Click1 / > < asp:ImageButton ID = btn_spam runat = server ToolTip = 垃圾邮件 onclick = btn_spam_Click1 / > < / td > < / tr > < tr > < td colspan = 5 > < span class =' st_facebook_large' displayT ext =' Facebook' title = 在Facebook上分享此广告 > < / span > < span class =' st_googleplus_large' displayText =' Google +' title = 在G上分享此广告oogle + > < / span > < span class =' st_twitter_large' displayText =' Tweet' title = 在Twitter上分享此广告 > < / span > < span class =' st_linkedin_large' displayText =' LinkedIn' title = 在LinkedIn上分享此广告 > < / span > < span class =' st_email_large' displayText =' 电子邮件' title = 在电子邮件上分享此广告 > < / span > < span class =' st_sharethis_large' displayText =' ShareThis' title = 更多共享选项 > < / span > < / td > < / tr > < / table > < / ContentTemplate > < 触发器 > < asp:AsyncPostBackTrigger ControlID = btn_like EventName = 点击 / > < asp:AsyncPostBackTrigger ControlID = btn_favorite EventName = 点击 / > < asp:AsyncPostBackTrigger ControlID = btn_spam EventName = 点击 / > < / Triggers > < / asp:UpdatePanel > protected void btn_like_Click1( object sender,ImageClickEventArgs e) { if ( null == Sessi on [ advertise] ||会话[ advertise] == null ) { ScriptManager.RegisterStartupScript( this , typeof ( string ), 错误, alert('请登录喜欢这个广告。');,真); } else { ses = Session [ advertise]。ToString(); SqlCommand cmd = new SqlCommand( sps_checklike ,con); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue( @ ad_id,ad_id); cmd.Parameters.AddWithValue( @ email,ses); cmd.Parameters.Add( @ ERROR,SqlDbType.Int); cmd.Parameters [ @ ERROR]。Direction = ParameterDirection.Output; con.Open(); cmd.ExecuteNonQuery(); int s =( int )cmd.Parameters [ @ ERROR]。价值; con.Close(); if (s == 1 ) { SqlCommand cmd3 = new SqlCommand( sps_decreaselike,con); cmd3.CommandType = CommandType.StoredProcedure; cmd3.Parameters.AddWithValue( @ ad_id,ad_id); cmd3.Parameters.AddWithValue( @ email,ses); con.Open(); cmd3.ExecuteNonQuery(); con.Close(); btn_like.ImageUrl = http:// localhost:37698 / Finder / Images / likeinactive.png; LoadDetails(); } else { SqlCommand cmd2 = 新 SqlCommand( sps_increaselike,con); cmd2.CommandType = CommandType.StoredProcedure; cmd2.Parameters.AddWithValue( @ ad_id,ad_id); cmd2.Parameters.AddWithValue( @ email,ses); con.Open(); cmd2.ExecuteNonQuery(); con.Close(); btn_like.ImageUrl = http:// localhost:37698 / Finder / Images / likeactive.png; LoadDetails(); } } } 解决方案 在UpdatePanel1的任何按钮事件后使用refresh propery I have one table inside update panel, in which i show some data from database, some image buttons and some sharing icons(spam link removed). When my page loads it shows all information, buttons and share icons but as i click on botton the share icons hides. When i refresh page then its again shows. Why it is hiding when button click.<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional"><ContentTemplate><table><tr><td colspan="5"><asp:ImageButton ID="btn_like" runat="server" ToolTip="Like" onclick="btn_like_Click1" OnClientClick="Show('shareicons');" /><asp:ImageButton ID="btn_favorite" runat="server" ToolTip="Favorite" onclick="btn_favorite_Click1"/><asp:ImageButton ID="btn_spam" runat="server" ToolTip="Spam" onclick="btn_spam_Click1"/></td></tr><tr><td colspan="5"><span class='st_facebook_large' displayText='Facebook' title="Share this Ad on Facebook"></span><span class='st_googleplus_large' displayText='Google +' title="Share this Ad on Google+"></span><span class='st_twitter_large' displayText='Tweet' title="Share this Ad on Twitter"></span><span class='st_linkedin_large' displayText='LinkedIn' title="Share this Ad on LinkedIn"></span><span class='st_email_large' displayText='Email' title="Share this Ad on Email"></span><span class='st_sharethis_large' displayText='ShareThis' title="More Sharing Options"></span></td></tr></table></ContentTemplate><Triggers><asp:AsyncPostBackTrigger ControlID="btn_like" EventName="Click" /><asp:AsyncPostBackTrigger ControlID="btn_favorite" EventName="Click" /><asp:AsyncPostBackTrigger ControlID="btn_spam" EventName="Click" /></Triggers></asp:UpdatePanel>protected void btn_like_Click1(object sender, ImageClickEventArgs e) { if (null == Session["advertise"] || Session["advertise"] == null) { ScriptManager.RegisterStartupScript(this, typeof(string), "Error", "alert('Please login to Like this Advertisement.');", true); } else { ses = Session["advertise"].ToString(); SqlCommand cmd = new SqlCommand("sps_checklike", con); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@ad_id", ad_id); cmd.Parameters.AddWithValue("@email", ses); cmd.Parameters.Add("@ERROR", SqlDbType.Int); cmd.Parameters["@ERROR"].Direction = ParameterDirection.Output; con.Open(); cmd.ExecuteNonQuery(); int s = (int)cmd.Parameters["@ERROR"].Value; con.Close(); if (s == 1) { SqlCommand cmd3 = new SqlCommand("sps_decreaselike", con); cmd3.CommandType = CommandType.StoredProcedure; cmd3.Parameters.AddWithValue("@ad_id", ad_id); cmd3.Parameters.AddWithValue("@email", ses); con.Open(); cmd3.ExecuteNonQuery(); con.Close(); btn_like.ImageUrl = "http://localhost:37698/Finder/Images/likeinactive.png"; LoadDetails(); } else { SqlCommand cmd2 = new SqlCommand("sps_increaselike", con); cmd2.CommandType = CommandType.StoredProcedure; cmd2.Parameters.AddWithValue("@ad_id", ad_id); cmd2.Parameters.AddWithValue("@email", ses); con.Open(); cmd2.ExecuteNonQuery(); con.Close(); btn_like.ImageUrl = "http://localhost:37698/Finder/Images/likeactive.png"; LoadDetails(); } } } 解决方案 Use refresh propery after any button event for UpdatePanel1 这篇关于点击按钮隐藏共享图标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!