Click here to Skip to main content
15,892,005 members
Please Sign up or sign in to vote.
3.67/5 (2 votes)
See more: , +
hey all,
long story short:
I have a few links that represent project categories. on each of the links click, a datagrid on the same page gets populated with appropriate data. I wanna use ajax functionality, I use .net framework 4.5 with entity framework 5. I placed the links and gridview both in the same update panel but the page still refreshes when i click on any of the links.
Please let me know if you want me to paste any code parts to aid you in pointing the problem.
Many thanks in advance :)

ASPX CODE:

XML
<asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server"></asp:ToolkitScriptManager>
        <asp:UpdatePanel ID="UpdatePanel1" UpdateMode="Always" ChildrenAsTriggers="true" runat="server">
            <ContentTemplate>
                <div>
        <asp:DropDownList ID="DropDownList1" runat="server" ></asp:DropDownList>
        <asp:TextBox ID="TextBox1" runat="server" TextMode="Date" />
    </div>
                <asp:Repeater runat="server" ID="rptProjectStates">
                    <HeaderTemplate>
                        <ul>
                    </HeaderTemplate>
                    <ItemTemplate>
                        <li>
                            <asp:LinkButton ID="lbProjectStatus" Text='<%#Eval("ProjectStatusTypeName") %>' 

OnClick="lbProjectStatus_Click" runat="server" /></li>
                    </ItemTemplate>
                    <FooterTemplate>
                        </ul>
                    </FooterTemplate>
                </asp:Repeater>
                <asp:GridView runat="server" ID="gvProjects">
                    <Columns>
                        <asp:TemplateField>
                            <HeaderTemplate>
                                <asp:Label Text="Project No" runat="server" />
                                <br />
                                <asp:TextBox runat="server" ID="txtFilterProjID" OnTextChanged="txtFilterProjID_TextChanged" AutoPostBack="true" />
                            </HeaderTemplate>
                            <ItemTemplate>
                                <asp:Label Text='<%#Eval("Title") %>' runat="server" />
                            </ItemTemplate>
                        </asp:TemplateField>
                    </Columns>
                </asp:GridView>
            </ContentTemplate>
        </asp:UpdatePanel>


BACK END CODE:

using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using SafatES.SPIS.DAL.ProjectServer;
using System.Configuration;
using SPIS.DATA;

namespace SPIS_Remake
{
    public partial class PSTest : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            PopulateStatusTypes();

            using (SPISDBOnlineEntities dc = new SPISDBOnlineEntities())
            {
                rptProjectStates.DataSource = dc.ProjectStatusTypes.ToList();
                rptProjectStates.DataBind();
            }
        }

        private void PopulateStatusTypes()
        {
            Uri pwaUri = new Uri("http://projects.safates.com:80/");
            SafatES.SPIS.DAL.ProjectServer.Project projects= new SafatES.SPIS.DAL.ProjectServer.Project(pwaUri, ConfigurationSettings.AppSettings["PSIUsername"].ToString(), ConfigurationSettings.AppSettings["PSIPassword"].ToString(), ConfigurationSettings.AppSettings["PSIDomain"].ToString());

            /* Populate Branches */
            DataTable dtProjectStatus = Helpers.DynamicGetLookUpTable("SafatES-Clients");
            DropDownList1.DataSource = dtProjectStatus;
            DropDownList1.DataValueField = "LT_STRUCT_UID";
            DropDownList1.DataTextField = "LT_VALUE_TEXT";
            DropDownList1.DataBind();

            SafatES.SPIS.DAL.ProjectServer.Helpers.DisposeClients();
        }

        protected void txtFilterProjID_TextChanged(object sender, EventArgs e)
        {

        }

        protected void lbProjectStatus_Click(object sender, EventArgs e)
        {
            LinkButton lb = (LinkButton)sender;
            using (var dc = new SPISDBOnlineEntities())
            {
                gvProjects.DataSource = (from projs in dc.ViewProjects
                                         where projs.ProjectStatusTypeName == lb.Text
                                         select projs).ToList();
                gvProjects.DataBind();
            }
        }

        
    }
}
Posted
Updated 3-Feb-14 6:43am
v2
Comments
JoCodes 3-Feb-14 12:09pm    
Can you show the code?
Reda Makarem 3-Feb-14 12:46pm    
added markup and code :)
JoCodes 3-Feb-14 12:49pm    
Can you try with UpdateMode="Conditional" and use asychronous trigger for dropdown?
Reda Makarem 3-Feb-14 13:12pm    
problem is i want the changes to take place when a link in the repeater is clicked, not on dropdown list selection... any ideas?
JoCodes 3-Feb-14 13:20pm    
Ok, now got it after seeing your codebehind. I have added a solution. Can you try it out and revert to me?

First Change the UpdateMode="Always" to UpdateMode="Conditional" .

Then register Linkbutton Control inside the repeater for Asynchronous postback.

Something like

C#
using (SPISDBOnlineEntities dc = new SPISDBOnlineEntities())
            {
                rptProjectStates.DataSource = dc.ProjectStatusTypes.ToList();
                rptProjectStates.DataBind();
        foreach (RepeaterItem ri in rptProjectStates.Items)
                {
                    if (ri.ItemType == ListItemType.Item || ri.ItemType ==                          ListItemType.AlternatingItem)
                    {
                            LinkButton lb = ri.FindControl("lbProjectStatus") as LinkButton;
                            ToolkitScriptManager1.RegisterAsyncPostBackControl(lb);
                    }
                }
            }
 
Share this answer
 
Comments
Reda Makarem 3-Feb-14 13:34pm    
Thank you for your response. After applying what you mentioned above, everything stopped working
if you have any idea how to get around this please let me know
JoCodes 3-Feb-14 13:41pm    
I just tried with a repeater and a linkbutton inside it and a gridview binding on linkbutton click.It seemed to work . Any particular reason ChildrenAsTriggers="true" has been added?If not required can you remove it and check?
Reda Makarem 3-Feb-14 13:50pm    
i did remove that but no change man. When i debugged the code, the datasource seems to have items (80 items) but nothing gets displayed. Sorry for bugging you and thanks for all your help
hello all...
I have finally managed to solve the problem. All I had to do is to call the update method of the updatepanel after binding the datagrid. If anyone knows why that had to be done please let me know. Many thanks to all :)
 
Share this answer
 
v2
Comments
JoCodes 4-Feb-14 2:07am    
Glad to hear that. :)
Java
Import java.IO.*;

public class Answer
{
public static void main(String[] args)
{
System.out.println("Helo World!");
}
}
 
Share this answer
 
Comments
Reda Makarem 3-Feb-14 13:34pm    
very smart/mature

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