Click here to Skip to main content
Rate this: bad
good
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">
        <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>
 

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 9-Apr-13 1:13am
Edited 9-Apr-13 1:18am
CHill6066.9K
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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

--Amit
  Permalink  
v2
Comments
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.
 
--Amit
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.
 
--Amit
arbaaz jalil at 9-Apr-13 7:38am
   
Thanks Amit !
_Amy at 9-Apr-13 7:41am
   
Welcome. :)
Rate this: bad
good
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()
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.
  Permalink  

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

  Print Answers RSS
0 Mathew Soji 274
1 BillWoodruff 270
2 Afzaal Ahmad Zeeshan 244
3 Sergey Alexandrovich Kryukov 240
4 Raul Iloc 160
0 OriginalGriff 6,219
1 Sergey Alexandrovich Kryukov 5,853
2 DamithSL 5,103
3 Manas Bhardwaj 4,549
4 Maciej Los 3,845


Advertise | Privacy | Mobile
Web03 | 2.8.1411019.1 | Last Updated 9 Apr 2013
Copyright © CodeProject, 1999-2014
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