Click here to Skip to main content
15,886,017 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have a GridView within which i have a image button and a label next to it. When i click on the imagebutton the value of the label gets changed to 20 (example). But problem is that when i do this the page moves to the top, or may be the complete GridView reloads or entire page reloads i am not sure. I just want to update that one label which is next the image button.
I tried using UpdatePanel and all but still no luck.


XML
<asp:ImageButton ID="lnklike" runat="server" ImageUrl="~/Images/thumbsup.png" height="20px" Width="20px" CommandName="like" CommandArgument='<%# Eval("ScrapId")%>'/>

                <asp:UpdatePanel runat="server" id="UpdatePanel" updatemode="Conditional">
        <Triggers>
            <asp:AsyncPostBackTrigger controlid="lnklike" eventname="Click" />
        </Triggers>
            <ContentTemplate>
                &nbsp;<asp:Label ID="Label1" runat="server" Text='<%# Controls_GetUserScraps.abc((int)Eval("ScrapId")) %>' />

     </ContentTemplate>
        </asp:UpdatePanel>



C#
protected void GridViewRowCommand(Object sender, GridViewCommandEventArgs e)
    {

        var scrapId = Int32.Parse(e.CommandArgument.ToString());
        
        
        switch (e.CommandName)
        {
            case "like":
                GridViewRow row = (GridViewRow)(((ImageButton)e.CommandSource).NamingContainer);

    int index = row.RowIndex;

                string chklike = "select likestatus from tbl_like where fromid='" + Session["UserId"] + "' and scrapid='" + scrapId + "'";
                int a = dbo.GetLikesMethod(chklike);
                string chkthumbsdown = "select thumbsdownstatus from tbl_like where fromid='" + Session["UserId"] + "' and scrapid='" + scrapId + "'";
                int b = dbo.GetLikesMethod(chkthumbsdown);

                if (a == 0 && b == 0)
                {
                    string sendlike = "insert into tbl_like (ScrapId,FromId,LikeStatus) values('" + scrapId + "','" + Session["UserId"] + "',1)";
                    dbo.insert(sendlike);
                    
                    Label lbl=(Label)GridViewUserScraps.Rows[index].FindControl("Label1");
                    lbl.Text = "20";
                    //GetUserScraps(int.Parse(Request.QueryString["Id"].ToString()));
                }
Posted
Updated 9-Apr-13 0:18am
v2

You need to set MaintainScrollPositionOnPostback to true Property in @page directive.
E.g.:
ASP.NET
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" MaintainScrollPositionOnPostback="true" %>



--Amit
 
Share this answer
 
v2
Comments
arbaaz jalil 9-Apr-13 6:35am    
I am getting this error :
Error 21 Error parsing attribute 'maintainscrollpositiononpostback': Type 'System.Web.UI.UserControl' does not have a public property named 'maintainscrollpositiononpostback'.
_Amy 9-Apr-13 6:37am    
You need to add this property in your aspx page which contains the user control.

FYI, user controls is not having @page directives.

--Amit
arbaaz jalil 9-Apr-13 7:34am    
Its working , Thanks Mate! Btw can you tell me whether i am reloading entire page and maintaining the scroll, or am i updating just that label right now with my code?
_Amy 9-Apr-13 7:36am    
Yeah, you are updating your label here.

--Amit
arbaaz jalil 9-Apr-13 7:38am    
Thanks Amit !
i also suffer from same problem then i used update panel like .
<asp:updatepanel id="updpnlRefresh" runat="server" updatemode="Conditional" xmlns:asp="#unknown">

Protected Sub UpdatePanels()
updPnlSalesLead.Update()
updpnlRefresh.Update()
End Sub

and i update this update panel from code behind on button click events and grid updation and editing events. my page does not post back and my scroll stick on same position even i click on any button.
 
Share this answer
 

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



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