Click here to Skip to main content
11,806,590 members (69,396 online)
Rate this: bad
Please Sign up or sign in to vote.
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.

<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">
            <asp:AsyncPostBackTrigger controlid="lnklike" eventname="Click" />
                &nbsp;<asp:Label ID="Label1" runat="server" Text='<%#"ScrapId")) %>' />

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)";
                    Label lbl=(Label)GridViewUserScraps.Rows[index].FindControl("Label1");
                    lbl.Text = "20";
Posted 9-Apr-13 0:13am
Edited 9-Apr-13 0:18am
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

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

arbaaz jalil at 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 at 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.

arbaaz jalil at 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 at 9-Apr-13 7:36am
Yeah, you are updating your label here.

arbaaz jalil at 9-Apr-13 7:38am
Thanks Amit !
_Amy at 9-Apr-13 7:41am
Welcome. :)
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

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()
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.

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

  Print Answers RSS
0 ppolymorphe 205
1 OriginalGriff 175
2 Richard Deeming 175
3 Sergey Alexandrovich Kryukov 170
4 Abhinav S 120
0 OriginalGriff 3,380
1 Maciej Los 1,990
2 CPallini 1,915
3 KrunalRohit 1,907
4 ppolymorphe 1,317

Advertise | Privacy | Mobile
Web04 | 2.8.151002.1 | Last Updated 9 Apr 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100