Dynamic Controls Postback Problem,
it taking much time to Load page when button click event Fire
My code:-
protected void link1_Click(object sender, EventArgs e)
{
DataTable dt2 = (DataTable)ViewState["PostId"];
HtmlButton link1 = sender as HtmlButton;
PressedButton.Value = link1.ID;
for (int i = 0; i < dt2.Rows.Count; i++)
{
HtmlButton btnlike1 = (HtmlButton)PnlTap.FindControl("link1" + i);
//if (btnlike1.Text == "Like")
{
//Your 1st Operation
Label lblpost = (Label)PnlTap.FindControl("lblPostid" + i);
if (PressedButton.Value != null)
{
if (PressedButton.Value == "link1" + i)
{
SqlCommand comd = new SqlCommand("SpMode_Mypost", con);
comd.CommandType = System.Data.CommandType.StoredProcedure;
comd.Parameters.AddWithValue("@PostId", Convert.ToInt64(lblpost.Text).ToString());
comd.Parameters.AddWithValue("@UserID", Session["Usid"].ToString());
comd.Parameters.AddWithValue("@SchoolMasterID", Session["QueryID"].ToString());
comd.Parameters.AddWithValue("@Mode", "SpInsertLikes");
con.Open();
comd.ExecuteNonQuery();
con.Close();
break;
}
}
//link1.Text = "unlike";
}
}
System.Threading.Thread.Sleep(2000);
Response.Redirect(Request.Url.AbsoluteUri);
}
protected void link2_Click(Object sender, EventArgs e)
{
//Thread.Sleep(5000);
DataTable dt2 = (DataTable)ViewState["PostId"];
///Button link2 = sender as Button;
HtmlButton link2 = sender as HtmlButton;
//if (link2.Text == "Comment")
{
for (int i = 0; i < dt2.Rows.Count; i++)
{
Panel pnl = (Panel)PnlTap.FindControl("Pnlcomment" + i.ToString());
TextBox text1 = (TextBox)PnlTap.FindControl("text1" + i);
if (link2.ID == "link2" + i.ToString())
{
text1.Focus();
//pnl.Visible = true;
// link2.Text = "Comment -";
break;
}
}
System.Threading.Thread.Sleep(1000);
}
}
protected void link3_Click(Object sender, EventArgs e)
{
HtmlButton link3 = sender as HtmlButton;
DataTable dt2 = (DataTable)ViewState["PostId"];
PressedButton3.Value = link3.ID;
for (int i = 0; i < dt2.Rows.Count; i++)
{
HtmlButton btnlike3 = (HtmlButton)PnlTap.FindControl("link3" + i);
//Your 1st Operation
Label lblpost = (Label)PnlTap.FindControl("lblPostid" + i);
if (PressedButton3.Value != null)
{
if (PressedButton3.Value == "link3" + i)
{
SqlCommand comd = new SqlCommand("SpMode_Mypost", con);
comd.CommandType = System.Data.CommandType.StoredProcedure;
comd.Parameters.AddWithValue("@PostId", Convert.ToInt64(lblpost.Text).ToString());
comd.Parameters.AddWithValue("@Mode", "Spdeletepost");
con.Open();
comd.ExecuteNonQuery();
con.Close();
break;
}
}
}
Response.Redirect(Request.Url.AbsoluteUri);
}