0
<asp:UpdatePanel runat="server" ClientIDMode="Static" ID="TasksUpdatePanel" UpdateMode="Conditional">
    <ContentTemplate>
        <asp:Panel ID="pnlDropDown" runat="server" ClientIDMode="Static" CssClass="pnlDropDown">
            <!-- TASK NAME -->
            <asp:DropDownList ID="ddlTaskName" CssClass="chosen-select" DataSourceID="dsPopulateTaskName" AutoPostBack="true" DataValueField="Task Name" runat="server" Width="100%" Font-Size="11px" AppendDataBoundItems="true" OnSelectedIndexChanged="ddlTaskName_onSelectIndexChanged">
                <asp:ListItem Text="All" Value="%"></asp:ListItem>
            </asp:DropDownList>

        </asp:Panel>
        <asp:GridView ShowHeaderWhenEmpty="false" AlternatingRowStyle-BackColor="#EBE9E9" AutoGenerateColumns="false" OnSorting="yourTasksGV_Sorting" AllowSorting="true" ID="yourTasksGV" runat="server" ClientIDMode="Static" EmptyDataText="You currently have no tasks assigned to you" OnRowDataBound="yourTasksGV_RowDataBound" OnRowCreated="yourTasksGV_RowCreated">
            <Columns>
                <asp:TemplateField HeaderStyle-Width="2%">
                    <ItemTemplate>
                        <asp:ImageButton ImageUrl="~/cies.png" runat="server" ID="btnShowDepend" OnCommand="btnShowDepend_Command" CommandName="TaskDepend" CommandArgument='<%#Eval("TestIt") %>' ToolTip="Click to view Dependencies" />
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:HyperLinkField HeaderStyle-Width="16%" Target="_self" DataNavigateUrlFields="Task Detail" DataTextField="Task Name" DataNavigateUrlFormatString="" HeaderText="Task Detail" SortExpression="Task Name" ItemStyle-CssClass="taskTableColumn" />
                <asp:BoundField HeaderStyle-Width="10%" DataField="Workgroup" HeaderText="Workgroup" SortExpression="Workgroup" ItemStyle-CssClass="taskTableColumn" />
                <asp:BoundField HeaderStyle-Width="7%" DataField="Status" HeaderText="Status" SortExpression="Status" ItemStyle-CssClass="taskTableColumn" />
            </Columns>
        </asp:GridView>
    </ContentTemplate>
    <%--<Triggers>
        <asp:AsyncPostBackTrigger ControlID="ddlTaskName" EventName="onSelectIndexChanged" />
    </Triggers>--%>
</asp:UpdatePanel>

Whenever the ddlTaskName_onSelectIndexChanged function is executed there is a full page postback rather than just updating the UpdatePanel

ddlTaskName_onSelectIndexChanged function:

protected void ddlTaskName_onSelectIndexChanged(object sender, EventArgs e)
{
    PullData(ViewState["sortExp"].ToString(), ViewState["sortOrder"].ToString(), false); //calls a function to update the GridView
}

With the above code, the page does a full postback rather than just partial (only update the GridView) whenever the index is changed in the ddlTaskName

What code can I add/modify to ensure the full postback isn't executed and only update the GridView on index changed.

Thought... Do I need to add them in two separate UpdatePanel?

If I uncomment the triggers, I get the following error: A control with ID 'ddlTaskName' could not be found for the trigger in UpdatePanel 'TasksUpdatePanel'.

I am attaching the dropdownlist to the Gridview like this:

Is it because of this:

protected void yourTasksGV_RowCreated(object sender, GridViewRowEventArgs e)
{
    if (e.Row.RowType == DataControlRowType.Header)
    {
        GridView hGrid = (GridView)sender;
        GridViewRow gvrRow = new GridViewRow(0, 0, DataControlRowType.Header, DataControlRowState.Insert);

        TableHeaderCell tcCellTask = new TableHeaderCell();
        tcCellTask.Controls.Add(ddlTaskName);
        gvrRow.Cells.Add(tcCellTask);

        yourTasksGV.Controls[0].Controls.AddAt(0, gvrRow);
    }
}
SearchForKnowledge
  • 3,663
  • 9
  • 49
  • 122
  • Have you tried wrapping your Gridview in another UpdatePanel and moving your current trigger into that? See here: http://www.asp.net/web-forms/overview/older-versions-getting-started/aspnet-ajax/understanding-asp-net-ajax-updatepanel-triggers – sr28 May 20 '15 at 15:16
  • You mean, have two separate UpdatePanel? One for the dropdown and one for the GridView? But shouldn't it be the same if they are in one. I am just surprised and baffled of why it can't find the ID when it exists. – SearchForKnowledge May 20 '15 at 15:18
  • Yes, 2 update panels. 1 round the dropdown and 1 round the Gridview. Then put the trigger in the Gridview update panel relating to the dropdown. – sr28 May 20 '15 at 15:27
  • I don't think that is the issue because I added the following: `` inside the above existing code and add the following: ` ` and that works fine for me. – SearchForKnowledge May 20 '15 at 15:34
  • So the dropdown still isn't being found as a valid control? Check the designer and see if it's showing up in there. Out of interest can you use the control name in the code behind? I had a similar issue where the control wasn't being added to the designer for some strange reason. – sr28 May 20 '15 at 15:47
  • It is there in the designer. I even did a rebuild to make sure it is... :/ and I can use it in code-behind. I updated my question. I am adding the ddl to the gridview. – SearchForKnowledge May 20 '15 at 15:52
  • I am moving around the ddl on rowcreated function and that is why it can't find it. Wow finally figured it out. But the updatepanel updates without the trigger. – SearchForKnowledge May 20 '15 at 15:57
  • It should update without the trigger if the control that triggers the update is already within the update panel. My suggestion was to try and workaround your issue. On first glance your code should have worked fine as is. – sr28 May 20 '15 at 16:00
  • It should until I played around with the code. because I am shifting the ddl control in rowcreated function it can't find it. I will post a sample. – SearchForKnowledge May 20 '15 at 16:01
  • Ah, looked at your update. Makes more sense now. You're effectively moving the ddl out of scope. – sr28 May 20 '15 at 16:03
  • Yes. But is that why the UpdatePanel doesn't kick off? and the page refreshes completely? – SearchForKnowledge May 20 '15 at 16:04
  • Have you seen this post? http://stackoverflow.com/questions/2138565/drop-down-list-in-update-panel-causing-full-postback – sr28 May 20 '15 at 16:10
  • Looks like it might be you asp:Panel with the attribute ClientIDMode="Static" – sr28 May 20 '15 at 16:12
  • @sr28 Thank you for your help. I am done trying. Nothing is working. I think it is because of the `RowCreated` function – SearchForKnowledge May 20 '15 at 17:46
  • 1
    Have you tried nesting the Gridview in it's own update panel within the current 1, and then setting the ddl as a trigger within the Gridview update panel? – sr28 May 21 '15 at 07:50
  • Testing that out now. Thanks. – SearchForKnowledge May 21 '15 at 12:25
  • I think because I am swapping place for the DDL, it always does a full page postback. – SearchForKnowledge May 21 '15 at 12:36
  • 1
    Try setting the ChildrenAsTriggers property on the outer updatepanel to false and the ChildrenAsTriggers property on the inner one to true. – sr28 May 21 '15 at 12:38
  • I separated the two updatepanel. And the ddl still doing a full page postback :/. I will share the updated code. – SearchForKnowledge May 21 '15 at 12:39

3 Answers3

2

your code seems fine. did you try to comment out asp:Panel tab? if you unccoment triggers, you need to put asp:UpdatePanel around gridview

c_c
  • 57
  • 1
  • 1
  • 4
1

As per this post it looks like your asp:Panel could be the culprit with the ClientIDMode="Static". Try changing this so it inherits.

Community
  • 1
  • 1
sr28
  • 4,728
  • 5
  • 36
  • 67
0

You'd need to specify ChildrenAsTriggers="true" in your UpdatePanel tag. The error you're getting is because your dropdown doesn't physically exist in the markup, which is what a Trigger line expects to find during compliation/runtime - instead, you are adding it dynamically as a control in your RowCreated function. It might be possible to, in that same function, add a trigger to the UpdatePanel dynamically, if you wanted to try that, instead.

vapcguy
  • 7,097
  • 1
  • 56
  • 52