+ Reply to Thread
Results 1 to 3 of 3
  1. #1
    manik's Avatar
    manik is offline Om Shanti! Recent Blog:
    Join Date
    Apr 2008
    Location
    Boston, USA
    Posts
    13,122
    Thanks
    742
    Thanked 674 Times in 543 Posts
    Blog Entries
    4
    Feedback Score
    4 (100%)

    Default LinkButton Inside a Repeater in an UpdatePanel Causes Full Postback - ASP .NET

    LinkButton Inside a Repeater in an UpdatePanel Causes Full Postback

    If you place LinkButton inside a repeater which is inside an UpdatePanel, you will get a full postback if you click on the LinkButton.

    Take this code for example:
    Code:
    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Test.aspx.cs" Inherits="MobInvestor3.Test" %>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
    </head>
    <body>
        <form id="form1" runat="server">
            <asp:ScriptManager ID="ScriptManager1" runat="server">
            </asp:ScriptManager>
            <div style="width:35px;height:800px;background:yellow;">&nbsp;</div>
            <asp:UpdatePanel ID="UpdatePanel2" runat="server" UpdateMode="Conditional">
                <ContentTemplate>
                    <p>Update Panel 2</p>
                    <p><asp:LinkButton ID="LinkButton2" Text="LinkButton OUTSIDE REPEATER 1" runat="server" /></p>                
                    <p><asp:LinkButton ID="LinkButton1" Text="LinkButton OUTSIDE REPEATER 2" runat="server" /></p>
                    <p><asp:Button ID="Button2" runat="server" Text="INSIDE UpdatePanel 2..." /></p>
                    <p><asp:LinkButton ID="LinkButton3" Text="LinkButton Without ID" runat="server" /></p>
                    <asp:Repeater ID="rpt" runat="server">
                        <HeaderTemplate><hr /></HeaderTemplate>
                        <ItemTemplate>
                            
                            <p><asp:LinkButton ID="lb" Text="LinkButton INSIDE REPEATER" runat="server" /></p>
                        </ItemTemplate>
                        <SeparatorTemplate>
                            <hr />
                        </SeparatorTemplate>
                    </asp:Repeater>
                </ContentTemplate>
            </asp:UpdatePanel>  
    
        </form>
    </body>
    </html>
    On code behind use this for testing:
    Code:
    protected void Page_Load(object sender, EventArgs e)
            {
                ArrayList al = new ArrayList();
                al.Add("1");
                al.Add("1");
    
                rpt.DataSource = al;
                rpt.DataBind();            
            
            }
    On the rendered page if you click on the link button lb (Linkbutton INSIDE REPEATER) you would get a full postback instead of partial rendering.

    Reason?
    I dont know the cause really.

    Solution?
    On code behind register the linkbutton inside the repeater for Asynchronous postback.
    Like this
    Code:
    protected void Page_Load(object sender, EventArgs e)
            {
                ArrayList al = new ArrayList();
                al.Add("1");
                al.Add("1");
    
                rpt.DataSource = al;
                rpt.DataBind();
                foreach (RepeaterItem ri in rpt.Items)
                {
                    if (ri.ItemType == ListItemType.Item || ri.ItemType == ListItemType.AlternatingItem)
                    {
                        LinkButton lb = (LinkButton)ri.FindControl("lb");
                        ScriptManager1.RegisterAsyncPostBackControl(lb);
                    }
                }
            
            }
    I heard some people get full postback if they put the ID of the linkbutton. You should check to make sure put an ID.
    Boston Web Developer LLC
    Free Classified Ads & BUSINESS/PROFESSIONAL SOCIAL NETWORK


  2. #2
    MuhammadBasit is offline Freshman
    Join Date
    Dec 2011
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Feedback Score
    0

    Smile You need to render unique IDs for each sever control

    to achieve this add this attribute to page directive

    <%@ page ClientIDMode="AutoID" %>

    and everything will be fine

    all Linkbuttons in Repeater inside an updatepanel will start pasrtial post back

    hopefully this will u......

    regards....
    Muhammad Basit

  3. #3
    MuhammadBasit is offline Freshman
    Join Date
    Dec 2011
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Feedback Score
    0

    Default

    in addition to upper post

    by following upper you do not need to register the linkbutton inside the repeater for Asynchronous postback.


Similar Threads

  1. Web Hosting - Inside the Datacenter
    By Nile Hadwards in forum Web Hosting
    Replies: 1
    Last Post: 03-24-2010, 08:28 AM
  2. Hello aLL....newbie inside :)
    By Axel.jr in forum Introductions
    Replies: 6
    Last Post: 12-05-2009, 12:44 PM
  3. Replies: 1
    Last Post: 12-17-2008, 08:04 AM
  4. Replies: 2
    Last Post: 12-09-2008, 07:47 PM
  5. Dwights Inside Presence
    By muazra in forum General Talk
    Replies: 1
    Last Post: 07-23-2008, 06:39 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts