Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET WebForms Ajax
hi all
in Aspx Page I Have :
<asp:LinkButton ID="LinkBtn1" runat="server" CssClass="Tag" ClientIDMode="Static" Visible='<%# SetVisible(Eval("Tag1"))%>'><%# SetTag(Eval("Tag1"))%></asp:LinkButton>
and myScript is below.Why $(this) is Unknown?
$('.Tag').mouseenter(function () {
    var t = $(this).html();
    var tagName2 = encodeURIComponent(t);
    $.ajax({
        url: 'Test2.aspx?Name=' + tagName2,
        success: function (data) {
            if (data == "")
                return;
            //in This Section $(this) is Unknown.Why?How To Access  $(this)
            $(this).append('<div class="TagComment2"> slm man khubam</div>');
alert('Test');//and alert Not Show!WHy?
        }
    });
Posted 13-Jun-13 22:52pm
Edited 14-Jun-13 3:29am
v3
Comments
Tadit Dash at 14-Jun-13 4:09am
   
Have you included the jQuery file in the aspx page?
Sunasara Imdadhusen at 14-Jun-13 7:57am
   
What is your problem??
Seyed Ahmad Mirzaee at 14-Jun-13 8:18am
   
$(this).append('<div class="TagComment2"> slm man khubam</div>');
if you Write in this Line alert('Test'); Alert is Not Show!Why?
Tadit Dash at 14-Jun-13 8:38am
   
That means it is not going to the success function.
 
Check your FireBug Console window of FireFox, if you see any errors or not.
Sergey Alexandrovich Kryukov at 14-Jun-13 13:17pm
   
A bug is found, please see my answer.
—SA

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Problem
 
I guess you are trying to insert the div after the LinkButton.
 
But you have used append method, which will append the div inside the LinkButton, which makes no sense.
 
And you have another problem of "this" object.
That is, when you are in Success function, it will refer to the object of Success method, not the element LinkButton.
 
Solution
  • So, you need to store the current object in a variable before any further operation, so that you can use that variable inside the Success function.
  • Use .insertAfter()[^] to insert any element after the LinkButton.
  • Ending brackets of mouseenter event is also missing.
 
The code will look something like below...
$('.Tag').mouseenter(function () {
    // Store element object in a variable.
    var currentElement = $(this);
    var t = currentElement.html();
    var tagName2 = encodeURIComponent(t);
 
    $.ajax({
        url: 'Test2.aspx?Name=' + tagName2,
        success: function (data) {
            if (data == "")
                return;
            
            // Now use currentElement here.
            $('<div class="TagComment2">slm man khubam</div>').insertAfter(currentElement);
            alert('Test');
        }
    });
}); // This brackets are missing in your code.
 
Suggestion
 
Check the FireBug Console window to check if there are any other issues or not.
  Permalink  
v3
Comments
Sergey Alexandrovich Kryukov at 14-Jun-13 15:29pm
   
My 5, and thank you again for correcting me.
—SA
Tadit Dash at 14-Jun-13 15:45pm
   
Most welcome.
Thanks Sergey Alexandrovich Kryukov... :)

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

  Print Answers RSS
0 OriginalGriff 285
1 DamithSL 265
2 CPallini 195
3 Maciej Los 175
4 George Jonsson 170
0 OriginalGriff 5,415
1 DamithSL 4,422
2 Maciej Los 3,820
3 Kornfeld Eliyahu Peter 3,470
4 Sergey Alexandrovich Kryukov 2,911


Advertise | Privacy | Mobile
Web04 | 2.8.141216.1 | Last Updated 14 Jun 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100