[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

08/04/2009 at 06:53AM PDT, ID: 24624655
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

8.0

AsyncPostBack with Accordion,DataList and LinkButtons

Asked by ivita in Programming for ASP.NET, .NET Framework 2.x

Tags: ASP.NET 2.0, ASP.NET AJAX Toolkit 20229, .NET 2.0, C#

(Using Asp.net 2.0 and the Ajax control toolkit ver 20229)
(in a Content page)

I've setup an accordion with a parent/child category structure. The header of the Accordion contains a parent category and when the accordion pane extends, all the child categories for that parent are listed.

In order to get the parent categories in the header I placed a LinkButton in the Accordion's header template and then bound it to a SqlDataSource that selects the necessary values.

To get the child categories I've placed a DataList(of LinkButtons) in the Accordion's content template and then bind the DataList during the Accordion's ItemDataBound event.

I've been trying the get all the LinkButtons to peform an async. postback with an update panel that contains a gridview.

Since all the LinkButtons are created dynamically, I used the ToolkitScriptManager1.RegisterAsyncPostBackControl() method to try and register the LinkButtons.

Whenever a LinkButton is clicked, the DataList OnItemCommand Event handler fires. The Gridview DataSource is set and it's DataBind() method is called. Then I call the UpdatePanel.Update() method.  The UpdatePanel update mode is set to Conditional.

The Async. Postback happens once (when the page loads and I try a LinkButton) and then performs a regular Postback on subsequent requests.

Does anyone know why this happens?

Thanks.
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
<cc1:Accordion ID="Accordion1" runat="server"          
DataSourceID="SqlDataSource1" 
onitemdatabound="Accordion1_ItemDataBound" >
    <HeaderTemplate>
        <asp:LinkButton ID="LinkButton1" runat="server" Text='<%# Eval("parent_name") %>' CommandName="pc" CommandArgument='<%# Eval("pid") %>'></asp:LinkButton>
    </HeaderTemplate>
    <ContentTemplate>
        <asp:DataList ID="DataList1" runat="server" OnItemCommand="c_click">
            <ItemTemplate>
                <asp:LinkButton ID="LinkButton2" runat="server" Text='<%# Eval("child_name") %>' CommandName="cc" CommandArgument='<%# Eval("cid") %>'></asp:LinkButton>
            </ItemTemplate>
        </asp:DataList>
    </ContentTemplate>
</cc1:Accordion>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" 
                    SelectCommand="getPCats" SelectCommandType="StoredProcedure" 
                    ConnectionString="myconnstring" 
                    ProviderName="myprovidername"></asp:SqlDataSource>
 
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
 .............................
<asp:UpdatePanel/>
 
 
protected void Accordion1_ItemDataBound(object sender, AccordionItemEventArgs e)
    {
 
        if (e.ItemType == AccordionItemType.Header)
        {
            // registers the Header LinkButtons as AsyncPostBackControls
            LinkButton lb = (LinkButton)e.AccordionItem.FindControl("LinkButton1");
            ToolkitScriptManager1.RegisterAsyncPostBackControl(lb);
        }
        
        if (e.ItemType == AccordionItemType.Content)
        {
 
 
            // populates the Content DataList based on the parent category
            DataRowView cv = (DataRowView)e.Item;
            int pc = int.Parse(cv.Row[0].ToString());
            DataList dl = (DataList)e.AccordionItem.FindControl("DataList1");
            try
            {
                dl.ItemDataBound += new DataListItemEventHandler(dl_ItemDataBound);
                dl.DataSource = getChildDataSource(pc);
                dl.DataBind();
            }
            catch (Exception ex)
            {
 
            }
        }
    }
 
    protected void dl_ItemDataBound(object sender, DataListItemEventArgs e)
    {
        // registers the DataList LinkButtons as AsyncPostBackControls
        LinkButton lb = (LinkButton)e.Item.FindControl("LinkButton2");
        ToolkitScriptManager1.RegisterAsyncPostBackControl(lb);
    }
 
    protected void c_click(object sender, CommandEventArgs e)
    {
        if (e.CommandName == "pc")
        {
            // binds the gridview to the data source for the parent category
            gvDataSource = getPCGVDataSource();
            gvDataSource.DataBind();
        }
        else if (e.CommandName == "cc")
        {
            // binds teh gridview to the datasource for the child category
            gvDataSource = getCCGVDataSource();
            gvDataSource.DataBind();
 
        }
 
        UpdatePanel1.Update();
    }
 
Keywords: AsyncPostBack with Accordion,Data…
 
Loading Advertisement...
 
[+][-]08/05/09 02:21 AM, ID: 25021401

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 30-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]08/06/09 07:36 AM, ID: 25033869

View this solution now by starting your 30-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: Programming for ASP.NET, .NET Framework 2.x
Tags: ASP.NET 2.0, ASP.NET AJAX Toolkit 20229, .NET 2.0, C#
Sign Up Now!
Solution Provided By: ivita
Participating Experts: 1
Solution Grade: A
 
 
 
Loading Advertisement...
20090824-EE-VQP-74 - Hierarchy / EE_QW_3_20080625