How to add click event to my div from code?

How to add click event to my div from code?

I am looking at clicking on a div that will be welcomed in the message box, do you want to delete it and β€œyes” or β€œno” in the field?

All of the code behind:

while (reader.Read()) { System.Web.UI.HtmlControls.HtmlGenericControl div = new System.Web.UI.HtmlControls.HtmlGenericControl("div"); div.Attributes["class"] = "test"; //div.Style["float"] = "left"; div.ID = "test"; Image img = new Image(); img.ImageUrl = String.Format("{0}", reader.GetString(1)); // this line needs to be represented in sql syntax //img.ImageUrl = "~/userdata/2/uploadedimage/batman-for-facebook.jpg"; img.AlternateText = "Test image"; div.Controls.Add(img); div.Controls.Add(ParseControl(String.Format("&nbsp&nbsp "+"{0}", reader.GetString(0)))); div.Style["clear"] = "both"; test1.Controls.Add(div); } 

can you add a click event to it, if so?

+4
source share
2 answers

This link should summarize: http://davidhayden.com/blog/dave/archive/2004/03/16/178.aspx

 c# _myButton.Attributes.Add("onclick", "return confirm_delete();"); javascript: function confirm_delete() { if (confirm("Are you sure you want to delete the custom search?")==true) return true; else return false; } 
+7
source
  div.Attributes.Add("onclick", DoSomething); 
+2
source

Source: https://habr.com/ru/post/1345599/


All Articles