Click here to Skip to main content
15,885,244 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
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">
                               
                                 class="fa fa-thumbs-o-up" id="lblLike">
                                        
                                            <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>
                                        
                                   
                                      ^__i class="fa fa-comments">
                                    <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);
       }
   }
Posted
Updated 6-Nov-17 5:48am

1 solution

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.
 
Share this answer
 
Comments
Umair Nafis 6-Nov-17 11:00am    
i tried but got the same result.
Umair Nafis 6-Nov-17 11:01am    
string uid = Request.QueryString["uid"].ToString();
string bid = Request.QueryString["bid"].ToString();
Response.Redirect(string.Format("blog.aspx?uid={0}&bid={1}", uid, bid), false);
Karthik_Mahalingam 6-Nov-17 11:04am    
Why do you have to redirect ?
Umair Nafis 6-Nov-17 11:09am    
this is my page load code:

protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
if (Request.QueryString["uid"] != null)
{
getUser(Int64.Parse(new StandardModule().Decrypt(HttpUtility.UrlDecode(Request.QueryString["uid"])).ToString()));
if (Request.QueryString["bid"] != null)
{

blogg(Int64.Parse(new StandardModule().Decrypt(HttpUtility.UrlDecode(Request.QueryString["bid"])).ToString()));
bindblog();
FillCommentRepeater();
CommentsCount();
LikesCount();
pnlComment.Visible = true;

}
}

else if (Request.QueryString["bid"] != null)
{
blogg(Int64.Parse(new StandardModule().Decrypt(HttpUtility.UrlDecode(Request.QueryString["bid"])).ToString()));
bindblog();
CommentsCount();
}
else
{
bindblog();
}
}
}
Umair Nafis 6-Nov-17 11:08am    
when i remove redirect whatever data present on the page disappear. even url values not changing

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900