Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to configure a GridView CommandField to trigger Full Page Update in UpdatePanel
    primarykey
    data
    text
    <p>I have 2 user controls on my page. One is used for searching, and the other is used for editing (along with a few other things).</p> <p>The user control that provides the search functionality uses a GridView to display the search results. This GridView has a CommandField used for editing (showEditButton="true").</p> <p>I would like to place the GridView into an UpdatePanel so that paging through the search results will be smooth.</p> <p>The thing is that when the user clicks the Edit Link (the CommandField) I need to preform a full page postback so that the search user control can be hidden and the edit user control can be displayed.</p> <p><strong>Edit:</strong> the reason I need to do a full page postback is because the edit user control is outside of the UpdatePanel that my GridView is in. It is not only outside the UpdatePanel, but it's in a completely different user control.</p> <p>I have no idea how to add the CommandField as a full page postback trigger to the UpdatePanel. The PostBackTrigger (which is used to indicate the controls cause a full page postback) takes a ControlID as a parameter; however the CommandButton does not have an ID...and you can see why I'm having a problem with this.</p> <p><strong>Update on what else I've tried to solve the problem:</strong> I took a new approach to solving the problem. </p> <p>In my new approach, I used a TemplateField instead of a CommandField. I placed a LinkButton control in the TemplateField and gave it a name. During the GridView's RowDataBound event I retrieved the LinkButton control and added it to the UpdatePanel's Triggers.</p> <p>This is the ASP Markup for the UpdatePanel and the GridView</p> <pre><code>&lt;asp:UpdatePanel ID="SearchResultsUpdateSection" runat="server"&gt; &lt;ContentTemplate&gt; &lt;asp:GridView ID="SearchResultsGrid" runat="server" AllowPaging="true" AutoGenerateColumns="false"&gt; &lt;Columns&gt; &lt;asp:TemplateField&gt; &lt;HeaderTemplate&gt;&lt;/HeaderTemplate&gt; &lt;ItemTemplate&gt; &lt;asp:LinkButton ID="Edit" runat="server" Text="Edit"&gt;&lt;/asp:LinkButton&gt; &lt;/ItemTemplate&gt; &lt;/asp:TemplateField&gt; &lt;asp:BoundField ...... &lt;/Columns&gt; &lt;/asp:GridView&gt; &lt;/ContentTemplate&gt; &lt;/asp:UpdatePanel&gt; </code></pre> <p>In my VB.NET code. I implemented a function that handles the GridView's RowDataBound event. In this method I find the LinkButton for the row being bound to, create a PostBackTrigger for the LinkButton, and add it to the UpdatePanel's Triggers. <strike>This means that a PostBackTrigger is created for every "edit" LinkButton in the GridView</strike> <strong>Edit:</strong> this did not create a PostBackTrigger for Every "edit" LinkButton because the ID is the same for all LinkButtons in the GridView.</p> <pre><code>Private Sub SearchResultsGrid_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles SearchResultsGrod.RowDataBound If e.Row.RowType = DataControlRowType.Header Then ''I am doing stuff here that does not pertain to the problem Else Dim editLink As LinkButton = CType(e.Row.FindControl("Edit"), LinkButton) If editLink IsNot Nothing Then Dim fullPageTrigger As New PostBackTrigger fullPageTrigger.ControlID = editLink.ID SearchResultsUpdateSection.Triggers.Add(fullPageTrigger) End If End If End Sub </code></pre> <p>And instead of handling the GridView's RowEditing event for editing purposes i use the RowCommand instead. </p> <pre><code>Private Sub SearchResultsGrid_RowCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles SearchResultsGrid.RowCommand RaiseEvent EditRecord(Me, New EventArgs()) End Sub </code></pre> <p>This new approach didn't work at all because all of the LinkButtons in the GridView have the same ID. </p> <p>After reading the MSDN article on the <a href="http://msdn.microsoft.com/en-us/library/system.web.ui.updatepanel.triggers.aspx" rel="nofollow noreferrer">UpdatePanel.Triggers Property</a> I have the impression that Triggers can only be defined declaratively. This would mean that anything I did in the VB code wouldn't work.</p> <p>Any advise would be greatly appreciated.</p> <p>Thanks,</p> <p>-Frinny</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload