Search code examples
javascriptasp.netupdatepanelmodal-dialogscriptmanager

Modal Popup not working inside UpdatePanel


I have a gridview inside UpdatePanel. One of the column in gridview is link which when clicked should display modal (i am using zurb modal http://www.zurb.com/playground/reveal-modal-plugin). The problem is the modal only gets displayed only once when the link is clicked, the next time when the link is clicked it just refreshes the page. The modal should be displayed everytime when the link inside the gridview is clicked.

Modal Script:

function popupModal()
{
    $("a.link").click(function (e) {
        e.preventDefault();
        $('#myModal #modalContents').load($(this).attr('href'));
        $('#myModal').reveal();
    });
}

GridView:

<asp:ScriptManager ID="smgr" runat="server" EnablePartialRendering="true" />
<asp:UpdatePanel ID="upnlSearchResults" runat="server" RenderMode="Inline">
    <ContentTemplate>       
        <asp:GridView ID="gvResult" runat="server" AutoGenerateColumns="false">                   
            <Columns>
                <asp:BoundField DataField="EmployeeID" HeaderText="Employee ID"  />
                <asp:TemplateField HeaderText="">
                    <ItemTemplate>
                        </td></tr>
                        <tr>
                            <td colspan="10">
                                <a href="Department.aspx" class="link">Detail Information</a>
                            </td>
                        </tr>
                    </ItemTemplate>
                </asp:TemplateField>
            </Columns>
        </asp:GridView>
    </ContentTemplate>
    <Triggers>
        <asp:AsyncPostBackTrigger ControlID="btnSearch" />
    </Triggers>
</asp:UpdatePanel>

    <div id="myModal" class="reveal-modal">
         <div id="modalContents"></div>
         <a class="close-reveal-modal">&#215;</a>            
    </div>

Code To Bind GridView and Register Modal PopUp

protected void btnSearch_Click(object sender, ImageClickEventArgs e)
{
    var results = _presenter.GetEmployers();
    gvResult.DataSource = results;
    gvResult.DataBind();

    ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "popUp", "popupModal();", true);

}

Edit: I tried to debug javascript and the code breaks in line where it reveals the popup

   function popupModal()
    {
        $("a.link").click(function (e) {
            e.preventDefault();
            $('#myModal #modalContents').load($(this).attr('href'));
            $('#myModal').reveal(); -> [throws error in this line.]
        });
    }

Since i am using zurb modal, it consists of jquery.reveal.js file which consists of reveal function. The function popupModal is in my separate js file employee.js. Since the error message is something like this 'Object doesn't support property or method 'reveal' in IE, i am assuming once the popup modal gets displayed for the first time, it can't find the reveal function from the jquery.reveal.js file.

Can anyone help me fix this issue?

Sanjeev


Solution

  • ok finally found the solution. didn't know but you couldn't reference jquery.js file twice in the project. I had reference to my jquery.js file in Master file and i had same reference in my Department.aspx file. Got rid of duplicate jquery reference and it just worked fine.