Click here to Skip to main content
15,891,708 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
This is my code.I have three button in Gridview ,which is "addnewRow" ,"DeleteLastRow" and "Delete Row" when i click button the Page is Getting Post back to top of the page.its look terrible.how do i solve this
ASP.NET
 <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional" >
    <ContentTemplate>
 
                  <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"  
                      onrowcommand="GridView1_RowCommand" ShowFooter="True">
                      <Columns> 
                          <asp:TemplateField HeaderText="USER CODE">
                              <ItemTemplate>
                                  <asp:TextBox ID="txtusercode" runat="server" AutoPostBack="true" 
                                      ontextchanged="txtusercode_TextChanged"></asp:TextBox>
                              </ItemTemplate>
                          </asp:TemplateField> 
                          <asp:TemplateField HeaderText="PAID DATE">
                              <ItemTemplate>
                                  <asp:TextBox ID="txtpaiddate" runat="server" AutoPostBack="true" 
                                      ontextchanged="txtpaiddate_TextChanged"></asp:TextBox>
                              </ItemTemplate>
                              <FooterTemplate>
 <asp:Button ID="Button1" runat="server" onclick="Button1_Click"  Text="Add New Row" />
                              </FooterTemplate>
                          </asp:TemplateField>
                          <asp:TemplateField HeaderText="TOTAL AMOUNT">
                              <ItemTemplate>
                                  <asp:TextBox ID="txttotamt" runat="server"></asp:TextBox>
                              </ItemTemplate>
                              <FooterTemplate>
<asp:Button ID="btndeleterow" runat="server" onclick="btndeleterow_Click" Text="Delete Last Row" />  
                              </FooterTemplate>
                          </asp:TemplateField>
                          <asp:TemplateField HeaderText="DELETE  ROW">
                              <ItemTemplate>
   <asp:Button ID="BtndelCurrent" runat="server"  CommandArgument="<%#((GridViewRow)Container).RowIndex %>"  CommandName="DeleteRow" onclick="BtndelCurrent_Click" Text="Delete Row" />
                              </ItemTemplate>
                          </asp:TemplateField>
                      </Columns>
                  </asp:GridView>
                     </ContentTemplate>
    </asp:UpdatePanel>



Edited:

and one more thing is Gridview will bind For each and Every Button Click Event.
Posted
Updated 30-Apr-14 0:32am
v3

1 solution

You need to give Script manager before the update panel like this,

ASP.NET
 <asp:scriptmanager id="ScriptManager1" runat="server">
 </asp:scriptmanager>

<asp:updatepanel id="up1" runat="server">
  <contenttemplate>
    <!-- Your code here -->
  </contenttemplate>
</asp:updatepanel>
 
Share this answer
 
v2
Comments
Tom Marvolo Riddle 30-Apr-14 6:07am    
Hi bluesathish,without the scriptmanager you cannot run a page with updatepanel.It will throw a run time error.

OP already have a scriptmanager .The problem is,instead of partial rendering, the page is loading fully during postback .Hope you understand.

Cheers :)
bluesathish 30-Apr-14 6:16am    
Yes, but the OP problem is different. Read carefully, He wrote "when i click button the Page is Getting Post back to top of the page.its look terrible.how do i solve this " This happends in Gridview, i think he has the big gridview in his page or his page contains only a gridview!
Tom Marvolo Riddle 30-Apr-14 6:19am    
So what's the point of your solution?. You suggest OP to use scriptmanager but he has it already.
bluesathish 30-Apr-14 6:22am    
No no, my solution was not well enough i agreed that. I'm looking forward the solution from others/you, thats what i mentioned it in comment.
Tom Marvolo Riddle 30-Apr-14 6:27am    
My intention is to improve the solution.That's all

Cheers :)

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