Click here to Skip to main content
15,881,600 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a page with 10 gridviews on it. Each one has a modal popup extender which is used to enter information which is saved in a sql table for the gridview which should refresh asynchronously without a postback. I have ready many articles on this update panel. My goal is to get the page to not scroll the moment I click an add, edit or delete button on a row of a gridview. The add button is above the gridview in a header row. If I can just figure out how to get one of these to work, the same solution can be used on the other gridviews that I want updated asynchronously. I don't want the page to scroll, so the instant I click the EDIT button on the gridview, the popup should appear without page scrolling. I have yet to see this happen. Also, when the button on the popup to save the edited data is clicked, the page should not scroll up to the top and this always happens.

It all seemed quite simple to surround the gridview with the update panel. I have tried registering controls in the rowdatabound event but I could be doing that wrong.
Also, I should mention that in gridview5, (employer gridview), I added a column for a button, which when clicked opens up a popup for the gridview6 directly below which is the income gridview. There can be several categories of income for any particular employer in gridview5. So this button on each row of gridview5 should also not cause scrolling and when the save button of the popup control is clicked, the gridview6 should refresh without a postback. Should each gridview on my page have it's own separate update panel?

Here is my code for one of the gridviews along with the code behind :


VB
<pre>    <div style="overflow-x: scroll; overflow-y: scroll; height: 100px; width: 444px">
    <asp:UpdatePanel ID="updatepanel1" runat="server" UpdateMode="Conditional">
    <ContentTemplate>
    <asp:GridView ID="GridView2" runat="server" DataSourceID="SqlDataSource2" AutoGenerateColumns="False" CellPadding="2" HorizontalAlign="Center" OnRowDataBound="Gridview2_rowdatabound" OnRowCreated="Gridview2_RowCreated" DataKeyNames="PrevaddressID" RowStyle-Wrap="False" HeaderStyle-Wrap="False" ShowHeader="False" ShowFooter="True" FooterStyle-BackColor="Black" FooterStyle-ForeColor="Black" FooterStyle-Height="2">
    
    <FooterStyle BackColor="Black" ForeColor="Black" Height="2px"></FooterStyle>
    
    <HeaderStyle Wrap="False"></HeaderStyle>
    
    <PagerStyle Wrap="True" />
    <RowStyle HorizontalAlign="Center" />
    <Columns>
    <asp:TemplateField ItemStyle-Width="25px" HeaderText="">
    <ItemTemplate>
    <asp:ImageButton ID="editbtn2" ImageUrl="~/templates/images/small-pencil.jpg" runat="server" Width="18" Height="18" OnClick="editbtn2_Click" CommandArgument='<%# Eval("PrevaddressID") %>' CausesValidation="False" />
    </ItemTemplate>
    </asp:TemplateField>
    <asp:TemplateField ItemStyle-Width="25px" HeaderText="">
    <ItemTemplate>
    <asp:ImageButton ID="btn2Delete" ImageUrl="~/templates/images/delete-icon.png" runat="server" Width="18" Height="18" OnClick="btn2delete_Click" CausesValidation="False" />
    </ItemTemplate>
    </asp:TemplateField>
    <asp:BoundField DataField="Prevaddr" HeaderText="Prevaddr" SortExpression="Prevaddr" ItemStyle-Width="200px" />
    <asp:BoundField DataField="Prevaddryears" HeaderText="Prevaddyears" SortExpression="Prevaddyears" ItemStyle-Width="44px" />
    <asp:BoundField DataField="Prevaddrmonths" HeaderText="Prevaddrmonths" SortExpression="Prevaddrmonths" ItemStyle-Width="44px" />
    <asp:BoundField DataField="Prevaddrrentamt" HeaderText="Prevaddrrentamt" SortExpression="Prevaddrrentamt" ItemStyle-Width="58px" />
    </Columns>
    </asp:GridView>
    </ContentTemplate>
    </asp:UpdatePanel>
    </div>


VB
Protected Sub btn2Update_Click(ByVal sender As Object, ByVal e As EventArgs)
Dim cn As New SqlConnection(ConfigurationManager.ConnectionStrings("sqlConnectionString").ConnectionString)
Dim cmdupdate As New SqlCommand("UPDATE [PreviousAddresses] SET [ApplicantID] = @ApplicantID, [Borrower] = @Borrower, [Prevaddr] = @Prevaddr, [Prevunitdesignator] = @Prevunitdesignator, [Prevunitnum] = @Prevunitnum, [Prevaddrcity] = @Prevaddrcity, [Prevaddrstate] = @Prevaddrstate, [Prevaddrzip] = @Prevaddrzip, [Prevaddrcountry] = @Prevaddrcountry, [Prevaddrexpense] = @Prevaddrexpense, [Prevaddryears] = @Prevaddryears, [Prevaddrmonths] = @Prevaddrmonths, [Prevaddrrentamt] = @Prevaddrrentamt WHERE (([PrevaddressID] = @PrevaddressID))", cn)

cmdupdate.Parameters.AddWithValue("@PrevaddressID", HiddenField2.Value)
cmdupdate.Parameters.AddWithValue("@ApplicantID", Session("ApplicantID"))
cmdupdate.Parameters.AddWithValue("@Borrower", 1)
cmdupdate.Parameters.AddWithValue("@Prevaddr", txtborprevaddress.Text.Trim)
cmdupdate.Parameters.AddWithValue("@Prevunitdesignator", ddlborprevunittype.SelectedValue)
cmdupdate.Parameters.AddWithValue("@Prevunitnum", txtborprevunitnum.Text.Trim)
cmdupdate.Parameters.AddWithValue("@Prevaddrcity", txtborprevcity.Text.Trim)
cmdupdate.Parameters.AddWithValue("@Prevaddrstate", txtborprevstate.Text.Trim)
cmdupdate.Parameters.AddWithValue("@Prevaddrzip", txtborprevzip.Text.Trim)
cmdupdate.Parameters.AddWithValue("@Prevaddrcountry", ddlborprevcountry.SelectedValue)
cmdupdate.Parameters.AddWithValue("@Prevaddrexpense", rbborprevhousingexp.SelectedValue)
cmdupdate.Parameters.AddWithValue("@Prevaddryears", txtborprevyears.Text.Trim)
cmdupdate.Parameters.AddWithValue("@Prevaddrmonths", txtborprevmonths.Text.Trim)
cmdupdate.Parameters.AddWithValue("@Prevaddrrentamt", txtborprevrentamt.Text.Trim)
cn.Open()
cmdupdate.ExecuteNonQuery()
cn.Close()
lblresult2.Text = " Details Updated Successfully"
lblresult2.Visible = True
GridView2.DataBind()
Page.ClientScript.RegisterStartupScript(Me.GetType(), "alertscript", "<script>$('.TempAlert2').hide(5000);</script>")
End Sub


What I have tried:

I tried to register some of the controls, because that's what several posts I read said to do. This doesn't seem to help though. Perhaps I'm not doing it right? is it necessary to register the edit and delete buttons in the gridviews? The add row button is outside of the update panel.

Protected Sub GridView2_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView2.RowDataBound

If e.Row.RowType = DataControlRowType.DataRow Then

Dim gv2 As GridView = CType(FindControl("GridView2"), GridView)
ScriptManager1.RegisterAsyncPostBackControl(gv2)
Dim insert2 As ImageButton = CType(FindControl("inserbtn2"), ImageButton)
ScriptManager1.RegisterAsyncPostBackControl(insert2)
Dim edit2 As ImageButton = CType(FindControl("editbtn2"), ImageButton)
Dim sm As ScriptManager = ScriptManager.GetCurrent(Me)
sm.RegisterAsyncPostBackControl(insert2)

'ScriptManager1.RegisterAsyncPostBackControl(edit2)
Dim delete2 As ImageButton = CType(e.Row.FindControl("btn2Delete"), ImageButton)
delete2.OnClientClick = "return confirm('Are you sure you want to delete this mortgage from " & e.Row.Cells(2).Text & "?')"
'sm.RegisterAsyncPostBackControl(delete2)
ScriptManager1.RegisterAsyncPostBackControl(delete2)
End If
End Sub
Posted
Updated 1-Jul-21 4:43am
v3

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