How can I add a click event to my div from code behind?
Im looking upon clicking on the div to be greeted by a message box with would you like to delete this and a yes or no within the box?
All from 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("   "+"{0}", reader.GetString(0))));
div.Style["clear"] = "both";
test1.Controls.Add(div);
}
can you add a click event to it if so how?
To add a click event listener on div tag using JavaScript, we can call the addEventListener method on the selected div. to add a div with a class. Then we write: const div = document.
Button event is always trigger when you click the button but if you want to raise your button click event manually from code then you can use Button. PerformClick() from your code. Suppose on click of your Button1 you want to trigger Button2 click event then Please refer this[^] MSDN example.
To display or hide a <div> by a <button> click, you can add the onclick event listener to the <button> element. The onclick listener for the button will have a function that will change the display attribute of the <div> from the default value (which is block ) to none .
To add the click event in React using plain JavaScript, you need to use addEventListener() to assign the click event to an element. Create one <button> element as ref props so that it can be accessed to trigger the click event.
This link should sum it up: 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;
}
div.Attributes.Add("onclick", DoSomething);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With