Click here to Skip to main content
16,015,414 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
HTML
    @using (Ajax.BeginForm("_SubmitComment", "Blogs", new AjaxOptions
    {
        UpdateTargetId = "comments",
        OnSuccess = "OnSuccess",
        OnFailure = "OnFailure",
        LoadingElementId = "loading",
        OnBegin = "onSubmitBegin",
        InsertionMode = InsertionMode.Replace
    }))
    {  <!-- comment box --> 
        @Html.AntiForgeryToken()
        <div class="comment-box">
            <h3>
                Comments</h3>
            @if (@ViewData["StatusMessage"] != null && @ViewData["StatusMessage"].ToString().Trim().Length > 0)
            {
                <p class="graymessage" id="messagearea">
                         @ViewBag.StatusMessage.Trim()</p>
            }
            <ul>
                @foreach (var comment in Model.comment)
                {
                
                    <li>
                        <p>
                            @comment.CommentByName says</p>
                        <span>@comment.CommentDate at @comment.CommentTime</span>
                        <p>
                            @comment.Content
                            <br class="cl" />
                            <br class="cl" />
                            @if (!(@comment.IsAbused))
                            {
                                <a id="@comment.commentid.ToString()"  önclick="javascript:GetMyID(this);" 
                                style="text-decoration: none; color: blue; removed: pointer;" href="#inline1" class="various21"><!--Open Fancybox on click of this link-->
                                    Report Abuse</a>
                            }
                    else
                            {
                                <a  önclick="javascript:AlreadyMarked();" style="text-decoration: none; color: blue;
                                    cursor: pointer;">Report Abuse</a>
                            }
                        </p>
                    </li>
                }
            </ul>
            <div class="cl">
            </div>
      
<script type="text/javascript">
    $(document).ready(function () {


        $(".various21").fancybox();
     


    });</script>  </div>


It is working on first time on page load, but soon after submitting the partial view and getting response from controller, fancy box is not working. i tried to bind the fancybox code on "OnSuccess" of ajax.Beginfarm, but still no help.,


JavaScript
function OnSuccess() {
 try {
         
          
            $(".various21").on("click", function (args) {
                GetMyID(this);
                alert("heelll");
                fancybox()
            });
            $(".various2").on("click", function (args) {
                alert("heelll");
                GetMyID(this);
                fancybox()
            });
            $(".various2").on("click", function (args) {
                alert("heelll");
                GetMyID(this);
                fancybox()
            });
            $(".various21").on("click", function (args) {
                alert("heelll");
                GetMyID(this);
                fancybox()
            });
           


        } catch (ee) {
            alert(ee.Message);
        }
    }

may be this question is not understood to you due to the language or way to put the things, So please raise your questions relating this. I appreciate this.
I doing some code as well typing this question.
Posted
Updated 19-Dec-13 2:32am
v2

1 solution

add

JavaScript
$(".various21").fancybox();

to the onsuccess function. the ajax code is replacing the dom elements that fancybox setup.

note: you will have memory leaks with your code, as fancybox keeps references to dom objects, and while its events are unbound, these references are not. you might want to modify the fancybox to have a destroy or dispose method, that you can call to release the dom objects.

i have written fancybox code into partial view, which was causing loosing reference, i pull out the code from partial view and put into the normal view and removed all script also from the partial view. and it is working fine.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900