为什么lnkbtnlike.visible = false在ASP.NET C#实体框架中没有工作onclick事件? [英] Why lnkbtnlike.visible = false is not working onclick event in ASP.NET C# entity framework?

查看:72
本文介绍了为什么lnkbtnlike.visible = false在ASP.NET C#实体框架中没有工作onclick事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题是,当我点击LnkbtnLike的OnClick事件时,属性lnkbtnLike.visible = false无法正常工作。我调试代码并检查其值,它成功地取值false但是当点击事件后页面加载lnkbtnLike仍然可见为true。我无法理解为什么会发生这种情况?



我也在该页面上使用了转发器控件,但这些链接按钮不在重新开始。我想可能是因为转发器控制lnkbtnLike可见属性不起作用..请让我清楚这一点。谢谢!



我的尝试:



The Problem is when i click OnClick event of lnkbtnLike the property lnkbtnLike.visible = false is not working. i debug the code and check its value , it successfully takes the value false but when page loads after click event lnkbtnLike is still visible to true. I can't understand why this is happening?

I am also using a repeater control on that page but these link buttons are out of reapeater body . I Think may be because of repeater control lnkbtnLike visible property is not working.. Please let me clear this. Thank you !

What I have tried:

<div class="row">
                            <div class="col-sm-12">
                               
                                 
                                                <asp:Label ID="lblLike" runat="server"></asp:Label>
                                        
                                            <asp:LinkButton ID="lnkBtnLike" runat="server" Style="color: darkgray" OnClick="lnkBtnLike_Click">Likes</asp:LinkButton>
                                        
                                        
                                            <asp:LinkButton ID="lnkBtnUnlike" runat="server" OnClick="lnkBtnUnlike_Click" Visible="false">Liked</asp:LinkButton>
                                        
                                   
                                      
                                    <asp:Label ID="lblComment" runat="server"></asp:Label>
                            </div>
                        </div>







<asp:Panel ID="Panel1" runat="server">
                        <div class="row">
                            <asp:Repeater ID="rptComment" runat="server">

                                <ItemTemplate>


                                    <!-- main-comment-container -->
                                    <div class="comments-container">

                                        <ul class="comments-list">
                                            <li>
                                                <div class="comment-main-level">
                                                    <!-- Avatar -->
                                                    <div class="comment-avatar">

                                                        <img src="User/Attachments/userpro.jpg" alt="">
                                                    </div>
                                                    <!-- CommentBox -->
                                                    <div class="comment-box">
                                                        <div class="comment-head">
                                                            <h6 class="comment-name"><a href="#"><%#Eval("ProfileName") %></a></h6>
                                                            <span><%#Eval("CreatedDate") %></span>
                                                        </div>
                                                        <div class="comment-content">
                                                            <%# Eval("Comment") %>
                                                        </div>
                                                    </div>
                                                </div>
                                                <!-- Relpy-container -->
                                                <%--<ul class="reply-list">
                                                    <li>
                                                        <div class="comment-main-level">
                                                            <!-- Avatar -->
                                                            <div class="comment-avatar">
                                                                <img src="User/Attachments/userpro.jpg" alt=""></div>
                                                            <!-- CommenBox -->
                                                            <div class="comment-box">
                                                                <div class="comment-head">
                                                                    <h6 class="comment-name"><a href="">Biju Nakarmi</a></h6>
                                                                    <span>have 7 minutes</span>
                                                                </div>
                                                                <div class="comment-content">
                                                                    Lorem ipsum dolor sit amet, consectetur adipisicing elit. Velit omnis animi et iure laudantium vitae, praesentium optio, sapiente distinctio illo?
                                                                </div>
                                                            </div>
                                                        </div>
                                                        <!-- Relpy-container -->
                                                        <ul class="reply-list">
                                                            <li>
                                                                <div class="comment-main-level">
                                                                    <!-- Avatar -->
                                                                    <div class="comment-avatar">
                                                                        <img src="http://younginnovations.com.np/images/staffs/Rakesh.png" alt=""></div>
                                                                    <!-- CommentBox -->
                                                                    <div class="comment-box">
                                                                        <div class="comment-head">
                                                                            <h6 class="comment-name by-author"><a href="g">Rakesh Nunchen Pradhan</a></h6>
                                                                            <span>have 2 minutes</span>
                                                                        </div>
                                                                        <div class="comment-content">
                                                                            Lorem ipsum dolor sit amet, consectetur adipisicing elit. Velit omnis animi et iure laudantium vitae, praesentium optio, sapiente distinctio illo?
                                                                        </div>
                                                                    </div>
                                                                </div>
                                                            </li>
                                                            <!-- Relpy-container -->
                                                            <ul class="reply-list">
                                                                <li>
                                                                    <div class="comment-main-level">
                                                                        <!-- Avatar -->
                                                                        <div class="comment-avatar">
                                                                            <img src="http://younginnovations.com.np/images/staffs/Biju.png" alt=""></div>
                                                                        <!-- CommentBox -->
                                                                        <div class="comment-box">
                                                                            <div class="comment-head">
                                                                                <h6 class="comment-name"><a href="">Biju Nakarmi</a></h6>
                                                                                <span>have 10 minutes</span>
                                                                            </div>
                                                                            <div class="comment-content">
                                                                                Lorem ipsum dolor sit amet, consectetur adipisicing elit. Velit omnis animi et iure laudantium vitae, praesentium optio, sapiente distinctio illo?
                                                                            </div>
                                                                        </div>
                                                                    </div>
                                                                    <!-- Relpy-container -->
                                                                    <ul class="reply-list">
                                                                        <li>
                                                                            <div class="comment-main-level">
                                                                                <!-- Avatar -->
                                                                                <div class="comment-avatar">
                                                                                    <img src="http://younginnovations.com.np/images/staffs/Sweta.png" alt=""></div>
                                                                                <!-- Comment-box -->
                                                                                <div class="comment-box">
                                                                                    <div class="comment-head">
                                                                                        <h6 class="comment-name"><a href="">Sweta Shrestha</a></h6>
                                                                                        <span>have 30 minutes</span>
                                                                                    </div>
                                                                                    <div class="comment-content">
                                                                                        Lorem ipsum dolor sit amet, consectetur adipisicing elit. Velit omnis animi et iure laudantium vitae, praesentium optio, sapiente distinctio illo?
                                                                                    </div>
                                                                                </div>
                                                                            </div>
                                                                        </li>
                                                                    </ul>
                                                                </li>

                                                                <li>
                                                                    <div class="comment-main-level">
                                                                        <!-- Avatar -->
                                                                        <div class="comment-avatar">
                                                                            <img src="http://younginnovations.com.np/images/staffs/Rakesh.png" alt=""></div>
                                                                        <!-- CommentBox -->
                                                                        <div class="comment-box">
                                                                            <div class="comment-head">
                                                                                <h6 class="comment-name by-author"><a href="">Rakesh Nunchen Pradhan</a></h6>
                                                                                <span>have 10 minutes</span>
                                                                            </div>
                                                                            <div class="comment-content">
                                                                                Lorem ipsum dolor sit amet, consectetur adipisicing elit. Velit omnis animi et iure laudantium vitae, praesentium optio, sapiente distinctio illo?
                                                                            </div>
                                                                        </div>
                                                                    </div>
                                                                </li>
                                                            </ul>
                                                        </ul>
                                                    </li>
                                                </ul>--%>
                                            </li>

                                        </ul>
                                    </div>
                                </ItemTemplate>
                            </asp:Repeater>
                        </div>
                        </asp:Panel>







protected void lnkBtnLike_Click(object sender, EventArgs e)
   {
       try
       {
           using(database db = new database())
           {
               tblBlogLike tbl = new tblBlogLike();
               tbl.UserId = (Int64.Parse(new StandardModule().Decrypt(HttpUtility.UrlDecode(Request.QueryString["uid"])).ToString()));
               tbl.BlogId = (Int64.Parse(new StandardModule().Decrypt(HttpUtility.UrlDecode(Request.QueryString["bid"])).ToString()));
               tbl.Like = (Int64.Parse(new StandardModule().Decrypt(HttpUtility.UrlDecode(Request.QueryString["uid"])).ToString()));
               tbl.Status = "A";
               tbl.Flag = "NA";
               tbl.Remarks = "NA";
               tbl.CreatedDate = DateTime.Now;
               db.tblBlogLikes.Add(tbl);
               db.SaveChanges();
               db.Entry<tblBlogLike>(tbl).Reload();

               lnkBtnLike.Visible= false;
               lnkBtnUnlike.Visible= true;



               Response.Redirect(Request.Url.AbsoluteUri, false);



           }

       }
       catch(Exception ex)
       {
           Response.Redirect(ex.Message);
       }
   }

推荐答案

Response.Redirect(Request.Url.AbsoluteUri, false);



由于您将事件重定向到同一页面,因此会重新加载页面。因此可见性将设置为默认值。尝试删除该行并检查。


Since you are redirecting the event to the same page, it reloads the page. so the visibility will set to the default value. try removing the line and check.


这篇关于为什么lnkbtnlike.visible = false在ASP.NET C#实体框架中没有工作onclick事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆