Click here to Skip to main content
15,886,518 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi guys,

I have asp.net web application in c#.

in which i'm using Repeaters on maximum pages,
On insertion, update or delete in repeater the whole page is reloading again.

I just want to load repeater.

Can any one plz help me.


Thanks
Posted
Comments
ZurdoDev 11-Feb-15 10:34am    
That is the way the web works. You need to put an UpdatePanel around the repeater or do some other asynchronous post so that it does not post the whole page.
Maciej Los 11-Feb-15 13:47pm    
+5!
abdul subhan mohammed 12-Feb-15 14:39pm    
Thanks for replying, RyanDev.
I have used updatePanel for my repeater, but the problem is... the updatePanel is not finding my edit/delete button which is in the repeater in each row.
ZurdoDev 12-Feb-15 14:40pm    
I don't know what that means.
Shridhar Gowda 11-Feb-15 12:16pm    
Drag and drop a script manager and an update panel from toolbox. Then place your repeater inside update panel. It works as you expect. i.e., ajax call.

As Shridhar Gowda says you need to use updatePanel control if you wish to refresh a part of page instead of reloading whole page.Here I am giving you a sample code.

In .aspx

ASP
<![CDATA[<%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true"
    CodeBehind="Default.aspx.cs" Inherits="WebApplicationUpdatePanel._Default" %>]]>

<asp:content id="HeaderContent" runat="server" contentplaceholderid="HeadContent" xmlns:asp="#unknown">
</asp:content>
<asp:content id="BodyContent" runat="server" contentplaceholderid="MainContent" xmlns:asp="#unknown">

    <asp:scriptmanager id="ScriptManager1" runat="server">
    </asp:scriptmanager>
    <asp:updatepanel id="UpdatePanel1" runat="server">
    <contenttemplate>
    <asp:repeater id="Repeater1" runat="server">
    <HeaderTemplate>

    <table style="border:1px solid #0000FF; width:500px" cellpadding="0">

    <tr style="background-color:#FF6600; color:#000000; font-size: large; font-weight: bold;">

    <td>

    ID

    </td>

        <td>

    NAME

    </td>

        <td>

    Roll

    </td>

    </tr>

    </HeaderTemplate>
     <itemtemplate>

    <tr style="background-color:#EBEFF0">

    <td>
   <asp:label id="lblID" runat="server" text="<%#Eval("ID") %>" />
    </td>
        <td>
<asp:label id="lblName" runat="server" text="<%#Eval("Name") %>" />
    </td>
        <td>
    <asp:label id="lblRoll" runat="server" text="<%#Eval("Roll") %>" />
    </td>
    <tr>
     </tr></tr></itemtemplate>

    <footertemplate>

    </footertemplate></table>

    
    </asp:repeater>
    
  

    </contenttemplate>
    <triggers>
    <asp:asyncpostbacktrigger controlid="btnAdd" eventname="Click" />
    </triggers>
    </asp:updatepanel>
      <h3>Entry</h3><br />
      <asp:label id="lblmsg" runat="server" forecolor="Green"></asp:label>
    Name<asp:textbox id="txtName" runat="server"></asp:textbox><br />
      Roll<asp:textbox id="txtRoll" runat="server"></asp:textbox><br />
            <asp:button id="btnAdd" runat="server" text="Add" onclick="btnAdd_Click" />
</asp:content>

In Code behind(.cs)


C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace WebApplicationUpdatePanel
{
    public partial class _Default : System.Web.UI.Page
    {
        BooksDBEntities db = new BooksDBEntities();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                BindToRepeater();
            }
        }

        void BindToRepeater()
        {
            Repeater1.DataSource = db.Students.ToList();
            Repeater1.DataBind();
        }

        protected void btnAdd_Click(object sender, EventArgs e)
        {
            if (txtName.Text != "" && txtRoll.Text != "")
            {
                string name = txtName.Text;
                string roll = txtRoll.Text;

                Student s = new Student();
                s.Name = name;
                s.Roll = roll;

                db.Students.AddObject(s);
                db.SaveChanges();
                lblmsg.Text = "Successfully Updated!";
                BindToRepeater();
            }
        
        }
    }
}


Hope it helps.And have look in Microsoft's msdn following link
<a href="https://msdn.microsoft.com/en-us/library/bb399001%28v=vs.140%29.aspx">Introduction to the UpdatePanel Control</a>
 
Share this answer
 
Hey,

You can use <asp:updatepanel xmlns:asp="#unknown"> from your aspx page. Update panel is not postback your page.
 
Share this answer
 

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