jqModal and jquery widget long shot

Posted by rod on Stack Overflow See other posts from Stack Overflow or by rod
Published on 2010-12-29T16:37:09Z Indexed on 2010/12/29 16:53 UTC
Read the original article Hit count: 349

Filed under:
|
|
|

Hi All,

I just started playing around with jquery widgets within my jqmodals in my mvc app. I know this may be a long shot but I'll take it.

Initially,

  1. I can click the Add link, get the alert ("which is the prize", watching too much tv), next click cancel to close modal and get the desired results.
  2. I can, then, click the Edit link and get the same desired results.
  3. However, if I click Edit link first then I try to click the Add link, "forget about it" I don't get the alert (which means my widget did not init).
  4. But I can still go back and click Edit and get the prize (the alert message).

ajax: "/Home/EditPrintAdLine" and ajax: "/Home/AddPrintAdLine" render the same web user control

Any ideas?

<%@ Page Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage" %>

<asp:Content ID="indexTitle" ContentPlaceHolderID="TitleContent" runat="server">
    Home Page
</asp:Content>

<asp:Content ID="indexContent" ContentPlaceHolderID="MainContent" runat="server">
    <h2><%= Html.Encode(ViewData["Message"]) %></h2>
    <p>
        To learn more about ASP.NET MVC visit <a href="http://asp.net/mvc" title="ASP.NET MVC Website">http://asp.net/mvc</a>.
    </p>

    <div id="printAdLineEditDialog" class="jqmWindow"></div>
    <div id="printAdDialog" class="jqmWindow"></div>

    <table>   
    <tr><td><a id="printAdLineItem" href="#">Add a Line Item</a></td></tr>
    <tr><td><a id="editPrintAdLine" href="#">Edit</a></td></tr>        
    </table>

    <script type="text/javascript">
        $(document).ready(function() {

            $.widget("ui.my_widget", { _init: function() { alert("My widget was instantiated"); } });

            // Add line 
            $('#printAdLineItem').click(function(e) {
                $('#printAdDialog').jqmShow(this);
                e.preventDefault();
            });

            $('#printAdDialog').jqm({
                ajax: "/Home/AddPrintAdLine",
                onLoad: function(hash) {                    
                    $('#PrintAdLine_RunDate').my_widget();
                }
            });

            // Edit line 
            $('#editPrintAdLine').click(function(e) {
                $('#printAdLineEditDialog').jqmShow(this);
                e.preventDefault();
            });

            $('#printAdLineEditDialog').jqm({
                ajax: "/Home/EditPrintAdLine",
                onLoad: function(hash) {
                    $('#PrintAdLine_RunDate').my_widget();
                }
            });
        });
    </script>

</asp:Content>

© Stack Overflow or respective owner

Related posts about jQuery

Related posts about asp.net-mvc