........................................................
SqlConnection sqcon = new SqlConnection("Data Source=ADMIN-PC;Initial Catalog=raj;Integrated Security=True");
protected void Page_Load(object sender, EventArgs e)
{
if (IsPostBack)
{
BindRepeaterData();
}
Validate();
}
protected void Button1_Click(object sender, EventArgs e)
{
sqcon.Open();
SqlCommand cmd =new SqlCommand("insert into repeter_demo(User_Name,Subject,comment,Post_Date)values(@User_Name,@subject,@Comment,@Post_Date )", sqcon);
cmd.Parameters.AddWithValue("@User_Name", TextBox1.Text);
cmd.Parameters.AddWithValue("@Subject", TextBox2.Text);
cmd.Parameters.AddWithValue("@Comment", TextBox3.Text);
cmd.Parameters.AddWithValue("@Post_Date", DateTime.Now);
cmd.ExecuteNonQuery();
sqcon.Close();
TextBox1.Text = string.Empty;
TextBox2.Text = string.Empty;
TextBox3.Text = string.Empty;
BindRepeaterData();
}
//Bind Data to Repeater Control
protected void BindRepeaterData()
{
sqcon.Open();
SqlCommand cmd = new SqlCommand("select * from repeter_demo Order By Post_Date", sqcon);
DataSet ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter(cmd);
da.Fill(ds);
Rpt.DataSource = ds;
Rpt.DataBind();
sqcon.Close();
}
}
after each post back new row of repeater show on the page. while controls are empty .
im using this code at designing phase
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
how will i get rid of this problem .
at out put i want to clear repeter clear.

Riddhi ValechaPosted Jun 15, 2013, 1:01 AM
On Page_Load Event, put the code in the IF-Condition
Page_Load()
{
if(Page.IsPostBack==false)
{
//Put logic here.
}
}
---
Rest of controls, say Button Click or Textbox TextChangedEvent, put the code as-
Button1_Clicl()
{
if(Page.IsPostBack==true)
{
//Put logic here.
}
}
----
Textbix1_TextChagedEvent()
{
if(Page.IsPostBack==true)
{
//Put logic here.
}
}
----------------
In short, Page.Ispostback will be false only on Page Load event. Rest, Page.IsPostback will be true.