In my below code when is button clicked the textbox value is being added to the database and the same is displayed in the DataBinder are reloading the page. Well, just like chat script I need whole process to be done without postback. So, how to pass the value from textbox to DataBinder without reloading the page. i.e. How to perform Button Click such that it do not postback.
protected void Page_Load(object sender, EventArgs e)
{
string MyConString = "DRIVER={MySQL ODBC 3.51 Driver};" + "SERVER=localhost;" + "DATABASE=repeater;" + "UID=root;" + "PASSWORD=****;" + "OPTION=3";
OdbcConnection MyConnection = new OdbcConnection(MyConString);
try
{
MyConnection.Open();
OdbcCommand cmd = new OdbcCommand("Select message from table1", MyConnection);
OdbcDataReader dr = cmd.ExecuteReader();
ArrayList values = new ArrayList();
while (dr.Read())
{
if (!IsPostBack)
{
string ep = dr[0].ToString();
values.Add(new PositionData(ep));
Shout_Box.DataSource = values;
Shout_Box.DataBind();
}
}
}
catch
{
}
}
protected void Button1_Click(object sender, EventArgs e)
{
string MyConString = "DRIVER={MySQL ODBC 3.51 Driver};" + "SERVER=localhost;" + "DATABASE=repeater;" + "UID=root;" + "PASSWORD=*****;" + "OPTION=3";
OdbcConnection MyConnection = new OdbcConnection(MyConString);
OdbcCommand cmd = new OdbcCommand("INSERT INTO table1(message)VALUES(?)", MyConnection);
cmd.Parameters.Add("@email", OdbcType.VarChar, 255).Value = TextBox1.Text;
MyConnection.Open();
cmd.ExecuteNonQuery();
MyConnection.Close();
}
A quick and dirty way would be to use an Update Panel. It would appear to your end-users to occur without a postback and you would only need to make minor changes to your page.
More information: Introduction to the UpdatePanel control (MSDN)