سؤال

I have a property string OnClientClick and this contains a javascript string supplied by the user of my Ajax server control (this is similar to ImageButton mapping OnClientClick to the actual html tag's onClick).

My questions are:

  1. How do I achieve this mapping and cause my tag to output onClick based on what's been supplied for OnClientClick?
  2. If my tag is a span element, would onClick trigger when a child element is clicked (e.g. input type="image" tag)?
هل كانت مفيدة؟

المحلول

  1. Try adding the attribute onclick to your server user control.

    Control.Attributes.Add("onclick","NameOfYourJSfunction or Javascript code here.")

  2. The click event will bubble up the dom unless you have an event handler between the clicked element and the span element that suppresses propagation

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top