Make any button on the page as a trigger for an asp.net UpdatePanel other than its sibling or child postback controls -


consider following code fragment:

<div>     <asp:button runat="server" id="trickyuptrigger" text="tricky update" />     <div>         <asp:button runat="server" id="normaluptrigger" onclick="normaluptrigger_click" text="normal update" />         <asp:updatepanel runat="server">             <triggers>                 <asp:asyncpostbacktrigger controlid="normaluptrigger" />             </triggers>             <contenttemplate>                 <asp:label runat="server" id="changeablelabel" text="change me"></asp:label>             </contenttemplate>         </asp:updatepanel>     </div> </div> 

now make button with id of trickyuptrigger trigger of updatepanel. or, devise mechanism (probably... using javascript?) when button clicked updatepanel updates without full page postback.

if want update updatepanel when clicking on trickyuptrigger, can add button triggers list:

<asp:updatepanel runat="server">     <triggers>         <asp:asyncpostbacktrigger controlid="normaluptrigger" eventname="click" />         <asp:asyncpostbacktrigger controlid="trickyuptrigger" eventname="click" />     </triggers>     <contenttemplate>     ...     </contenttemplate> </asp:updatepanel> 


update

you asked code examples showing cases naming containers, concept comes play databound controls item templates, gridview , listview, , user controls. in examples below, use listview, each item separate naming container.

if wanted trigger update of panel button in listview item template, trigger not found @ runtime, , exception occur:

<asp:listview id="lstview" runat="server">     <itemtemplate>         <asp:button id="anothertrigger" runat="server" text="this trigger cannot found!" onclick="anothertrigger_click" />     </itemtemplate> </asp:listview> <asp:updatepanel runat="server">     <triggers>         <asp:asyncpostbacktrigger controlid="anothertrigger" eventname="click" />     </triggers> </asp:updatepanel> 

the reverse case (the updatepanel in listview item template, trigger button outside of listview) work, according tests, seems contradict note mention in comment:

<asp:listview id="lstview" runat="server">     <itemtemplate>         <asp:updatepanel runat="server">             <triggers>                 <asp:asyncpostbacktrigger controlid="anothertrigger" eventname="click" />             </triggers>         </asp:updatepanel>     </itemtemplate> </asp:listview> <asp:button id="anothertrigger" runat="server" text="this trigger works!" onclick="anothertrigger_click" /> 

finally, case updatepanel , trigger button both in listview item template works:

<asp:listview id="lstview" runat="server">     <itemtemplate>         <asp:button id="anothertrigger" runat="server" text="this trigger works!" onclick="anothertrigger_click" />         <asp:updatepanel runat="server" updatemode="conditional">             <triggers>                 <asp:asyncpostbacktrigger controlid="anothertrigger" eventname="click" />             </triggers>         </asp:updatepanel>     </itemtemplate> </asp:listview> 

you can notice set updatemode="conditional" panel in last example. setting, panel updated own triggers. if attribute set updatemode="always", panel updated not own triggers triggers of other updatepanels in page. default value updatemode="always" (as in code sample).


Comments

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -

java - Digest auth with Spring Security using javaconfig -