2
votes

i've a usercontrol with a gridview inside an updatepanel.

I've tried to trigger all the grid events because the master page should never post backed when i'm working on the gridview, but it doesn't work. The master page is always post backed!

What i can do?

This is myuser control asp.net code:

<asp:UpdatePanel ID="upFeatureCustomer" runat="server" ChildrenAsTriggers="true" >
<ContentTemplate>
<asp:GridView ID="gvFeatureCustomer" runat="server" DataKeyNames="Id"  
        AutoGenerateColumns="False" ClientIDRowSuffix="Id" 
    OnRowDataBound="dtgdResult_RowDataBound" ClientIDMode="Static" 
        ShowHeader="false">
    <Columns>
        <asp:TemplateField HeaderText="Nome" FooterText="Nome" SortExpression="Name">
            <ItemTemplate>
                <asp:DropDownList ID="ddlName" ClientIDMode="Predictable" runat="server" DataValueField="id" DataTextField="Name">
                </asp:DropDownList>
            </ItemTemplate>
        </asp:TemplateField>
        <asp:TemplateField HeaderText="Valore" FooterText="Valore" SortExpression="Value">
            <ItemTemplate>
                <asp:TextBox id="txtValue" AutoPostBack="true" runat="server" CssClass="auto-feature" OnTextChanged="txtValue_TextChanged"></asp:TextBox>
            </ItemTemplate>
        </asp:TemplateField>
         <asp:TemplateField HeaderText="Delete" FooterText="Delete" Visible="true" HeaderStyle-Width="25"
                ItemStyle-HorizontalAlign="Center">
                <ItemTemplate>
                    <asp:HyperLink ID="Delete" runat="server" NavigateUrl='<%# DataBinder.Eval(Container, "DataItem.Id", "javascript:openDeleteDialog(\"{0}\");")%>'
                        ImageUrl="~/images/delete2.png" ToolTip="Delete">
                    </asp:HyperLink>
                </ItemTemplate>
            </asp:TemplateField>
    </Columns>
</asp:GridView>

</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="gvFeatureCustomer" EventName="DataBinding" />
<asp:AsyncPostBackTrigger ControlID="gvFeatureCustomer" EventName="DataBound" />
<asp:AsyncPostBackTrigger ControlID="gvFeatureCustomer" EventName="Disposed" />
<asp:AsyncPostBackTrigger ControlID="gvFeatureCustomer" EventName="Init" />
<asp:AsyncPostBackTrigger ControlID="gvFeatureCustomer" EventName="Load" />
<asp:AsyncPostBackTrigger ControlID="gvFeatureCustomer" EventName="PageIndexChanged" />
<asp:AsyncPostBackTrigger ControlID="gvFeatureCustomer" EventName="PageIndexChanging" />
<asp:AsyncPostBackTrigger ControlID="gvFeatureCustomer" EventName="PreRender" />
<asp:AsyncPostBackTrigger ControlID="gvFeatureCustomer" EventName="RowCancelingEdit" />
<asp:AsyncPostBackTrigger ControlID="gvFeatureCustomer" EventName="RowCommand" />
<asp:AsyncPostBackTrigger ControlID="gvFeatureCustomer" EventName="RowCreated" />
<asp:AsyncPostBackTrigger ControlID="gvFeatureCustomer" EventName="RowDataBound" />
<asp:AsyncPostBackTrigger ControlID="gvFeatureCustomer" EventName="RowDeleted" />
<asp:AsyncPostBackTrigger ControlID="gvFeatureCustomer" EventName="RowDeleting" />
<asp:AsyncPostBackTrigger ControlID="gvFeatureCustomer" EventName="RowEditing" />
<asp:AsyncPostBackTrigger ControlID="gvFeatureCustomer" EventName="RowUpdated" />
<asp:AsyncPostBackTrigger ControlID="gvFeatureCustomer" EventName="RowUpdating" />
<asp:AsyncPostBackTrigger ControlID="gvFeatureCustomer" EventName="SelectedIndexChanged" />
<asp:AsyncPostBackTrigger ControlID="gvFeatureCustomer" EventName="SelectedIndexChanging" />
<asp:AsyncPostBackTrigger ControlID="gvFeatureCustomer" EventName="Sorted" />
<asp:AsyncPostBackTrigger ControlID="gvFeatureCustomer" EventName="Sorting" />
<asp:AsyncPostBackTrigger ControlID="gvFeatureCustomer" EventName="Unload" />
</Triggers>

</asp:UpdatePanel> 

ScriptManager is located inside the masterpage. Thank you.

3
Posted back how, when you do what? - rick schott
Try putting the UpdatePanel inside the ContentTemplate. - JBrooks
@rickschott I need to block the page post back when i'm working on the gridview. If i try triggering the button click event (for example) it's work, but with the gridview event doesn't. Any idea? - MassiCiaoCiao
@JBrooks How can i put the updatepanel inside the content tamplate if the contet template is an updatepanel section? - MassiCiaoCiao
Content template is a child of updatepanel. You can't take Jbrooks' advice. I think he mistook it for the ContentPlaceHolder element, which I just realized I did too. My answer below may no longer be relevant :( - Ross Brasseaux

3 Answers

1
votes

I've found out the solution. I've registered the asyncpostbackcontrol event at the page using the scriptmanager and it's work now!

The code is like this:

ScriptManager.GetCurrent(Page).RegisterAsyncPostBackControl(tbValue);

Thank you for helping me!

0
votes

Consider the way the content pages are rendered. The content page should normally not contain any code aside from the 'Page' tag used to reference the master page (and maybe a register tag for assemblies, etc). Any code you wish to appear outside the content tab should actually be placed in the master page.

This is a pretty good tutorial if you need some further help though:

You can sort of think of it like this: When you view an asp web page that is a content page, the master page is the actual page. It will always be the page that is displayed. When you place a ContentPlaceHolder in your content page, then it disregards any code within the corresponding ContentPlaceHolder on the master page. Likewise, if you place code within the content page but outside the ContentPlaceHolder, it will also be disregarded.

FYI: Like I said this is just my abstract understanding of it so please feel free to correct me if I am wrong!! :) Good luck with your site.

0
votes

in my case, Gridview RowCommand can be trigger by <asp:Button> in updatePanel ( I use Visual Studio 2012)