Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>It looks like you want to use event delegation. The main idea is that events bubble up and so you would attach your event handler outside of the update panel (perhaps to a div or table that the updatepanel resides in). This handler is in charge of all events it receives so even when your update panel posts back and a new textbox is rendered, you won't need to reattach the event handler. When the new textbox raises its event your existing event handler can try to handle it.</p> <p>The following is just one way of doing event delegation in javascript (using jquery and taken from <a href="http://www.danwebb.net/2008/2/8/event-delegation-made-easy-in-jquery" rel="nofollow noreferrer">http://www.danwebb.net/2008/2/8/event-delegation-made-easy-in-jquery</a>)</p> <pre><code>jQuery.delegate = function() { return function(e) { var target = $(e.target); if (target.attr("showCalendar")) { var calendar = $("#" + target.attr("showCalendar")); calendar.css("display", "block"); } } } $(document).ready(function() { $('#test').click($.delegate()); }); &lt;form id="form1" runat="server"&gt; &lt;asp:ScriptManager runat="server" EnablePartialRendering="true"/&gt; &lt;div id="test" style="width:100%;"&gt; &lt;asp:UpdatePanel runat="server"&gt; &lt;ContentTemplate&gt; &lt;input type="text" id="testText" showCalendar="testCalendarDiv" /&gt; &lt;div id="testCalendarDiv" style="display:none;"&gt; &lt;asp:Calendar runat="server" ID="testCalendar1"/&gt; &lt;/div&gt; &lt;/ContentTemplate&gt; &lt;/asp:UpdatePanel&gt; &lt;/div&gt; &lt;/form&gt; </code></pre> <p>In this simple example I register the delegate method on click of this div (the textbox and calendar are inside of this div). When you click the textbox the click event bubbles up to the div. The delegate method gets called and I check for the <em>showCalendar</em> attribute from the element who raised the event. If this attribute exists I find the element this attribute points to and update its display style. This is a pretty simple example but you could easily extend the delegate method to take in functions it will call based on some kind of rules you register.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload