Hope you can help.
I have aspx web application, which has a list populated from SQlite which is stored for mobile numbers
I have a button, which i lets me enable / disable a textbox - which all works.
Now, when I filter the view and click on "Edit" the page reloads.
The button/textbox is dynamically created from SQLite.
TextBox NES_editText = new TextBox();
NES_editText.CssClass = "editText";
NES_editText.Enabled = false;
NES_editText.Text = SQLReader["simName"].ToString();
NES_editText.ID = 300 + SQLReader["simNESID"].ToString();
Sim_Rows.Controls.Add(NES_editText);
Sim_Rows.Controls.Add(new LiteralControl("</div>")); // COL 2
Sim_Rows.Controls.Add(new LiteralControl("<div class=\"col col-3\" data-label=\"Edit Name\">"));
Button editButton = new Button();
editButton.CssClass = "editButton";
editButton.ID = SQLReader["simNESID"].ToString();
editButton.Click += new EventHandler(EditButton_Click);
Sim_Rows.Controls.Add(editButton);
Sim_Rows.Controls.Add(new LiteralControl("</div>")); // COL 3
Here is my edit button code
private void EditButton_Click(object sender, EventArgs e)
{
Button NES_Edit = sender as Button;
//TextBox NES_Text = new TextBox();
String TxtID;
//Response.Write(NES_Edit.ID);
foreach (Control obj in Sim_Rows.Controls)
{
if (obj is TextBox)
{
TxtID = obj.ID.Substring(3);
if (NES_Edit.ID == TxtID)
{
if (((TextBox)obj).Enabled == false)
{
((TextBox)obj).Enabled = true;
((TextBox)obj).Style.Add("border-bottom", "1px solid #000");
((TextBox)obj).Style.Add("width", "270px");
NES_Edit.CssClass = "button_enabled";
//Response.Write(NES_Edit.ID);
break;
}
else
{
((TextBox)obj).Enabled = false;
((TextBox)obj).Style.Remove("border-bottom");
NES_Edit.CssClass = "editButton";
SQL = "UPDATE Sims SET simName = @simName WHERE simNESID =" + NES_Edit.ID;
using (SQLiteConnection SQLCon = new SQLiteConnection(ConnectionString))
{
SQLiteCommand SQLCmd = new SQLiteCommand(SQL, SQLCon);
SQLCmd.Parameters.AddWithValue("@simName", ((TextBox)obj).Text );
try
{
SQLCon.Open();
SQLCmd.ExecuteNonQuery();
}
catch (SQLiteException Ex)
{
Response.Write(Ex.Message);
}
SQLCon.Close();
// SEND EMAIL
}
break;
}
}
}
}
}
When I filter the view, and i have two results and click on the edit, the page reloads.
Any way to stop that?