How to use the .show() of Ajax ModalPopUpExtender when ModalPopupExtender is within a gridview?

So I am using the ModalPopupExtender control from the Ajax control toolkit. It's my understanding that when I want to set the targetControlID to a button that's within a Gridview, that I need to put my ModalPopupExtender within the template that holds the button. In my case:

<asp:TemplateField>
           <ItemTemplate>
               <asp:LinkButton ID="lbtnDeleteWidget" runat="server" Text="Delete" CommandName="DeleteWidget" CommandArgument="<%# Container.DataItemIndex %>"></asp:LinkButton>
           </ItemTemplate>
           <FooterStyle HorizontalAlign="Right" />
           <FooterTemplate>
           <asp:Button ID="btnAddNewWidget" runat="server" CssClass="buttonStyle" Text="Add New Widget" onclick="btnAddNewWidget_Click"/>

           <ajaxToolkit:ModalPopupExtender ID="ModalPopupExtender1" runat="server"
           BackgroundCssClass="modalBackground"
           DropShadow="true"
           OkControlID="btnSaveWidget"
           CancelControlID="aCloseX"
           PopupControlID="Panel1"
           TargetControlID="btnAddNewWidget" /> 
      </FooterTemplate>
</asp:TemplateField>

Now, this is working well, the modal popup appears when the button is pressed and all is good. However, ModalPopUpExtender has the nasty habbit of closing the modal on postback. My pop up contains some DropDownLists that will have to do postbacks (it needs to execute some relevant code). Whenever this happens the modal closes.

A(n ugly) work around to this is using the show() function. For example, whenever a dropdownlist does a postback, the function ends with ModalPopupExtender1.Show();.

The problem:

ModalPopupExtender1 does not exist in my current context, because I defined it within the template field, so that it would work. How do I fix this? I wish to refer to my the ModalPopupExtender1 and use the .show() function to handle the postback issue.

Answers


Search for the nested modal popup extender like this.

VB.NET

Dim ModalPopupExtender1 = CType(YourGridView.FooterRow.Findcontrol("ModalPopupExtender1"), AjaxControlToolkit.ModalPopupExtender)
ModalPopupExtender1.Show()

C#

AjaxControlToolkit.ModalPopupExtender ModalPopupExtender1 = (AjaxControlToolkit.ModalPopupExtender)YourGridView.FooterRow.Findcontrol("ModalPopupExtender1");
ModalPopupExtender1.Show();

This will expose the buried control which is hidden in the item template.Let me know if this works.


Need Your Help

Problems with ordering Django objects

django

I have to you very stupid question, so sorry.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.