| « Reusable singleton in ASP.NET Context | jQuery Control Toolkit » |
Parameterized Modal Popup
Hello everyone,
Maybe some among of you ever had this issue : open a modal popup (here with AjaxControlToolkit), and being able to give it a parameter, the id of the control which opened the popup for example. It is entirely doable, it just need some code. The first thing to know it that with AjaxControlToolkit framework, there is a BehaviorID on any Extender. This property enables you to then manipulate this extender on the client side (in javascript). Let's have a look to the code before any explanation.
<asp:ModalPopupExtender runat="server" BehaviorID="myPopupBehavior" PopupControlId="myPopup" TargetControlId="dummyLB" /> <asp:Panel ID="myPopup" runat="server"> <asp:HiddenField runat="server" ID="myParameter" /> </asp:Panel> <asp:LinkButton ID="dummyLB" runat="server" style="display:none" /> <style type="text/javascript"> function openPopup(parameter) { $find("myPopupBehavior").show(); $get("<%= myParameter.ClientID %>").value=parameter; } </style>
After having seen the code, I guess you need some explanations. First of all, the first thing to know is that an AjaxControlToolkit extender always need a TargetControlID. I made an invisible LinkButton for that purpose. The second this to notice, is that in the panel which will be displayed, I have an hidden field. This is this field which would hold the value of my parameter. To assign my parameter, I made this javascript function which hides this assignment behavior. Thus, I have a reusable function to open that popup. Here is a sample use case :
<a onclick="openPopup('http://www.google.fr')>lien vers google</a>
With this code you also can have the value of your parameter on the server side because the hidden field is a server control !
Voilà, hope you enjoyed it.
Aucun commentaire pour le moment
Les commentaires sont fermés pour cet article.