Results 1 to 7 of 7

Thread: [RESOLVED] Jquery to PageMethods

  1. #1

    Thread Starter
    Frenzied Member FishGuy's Avatar
    Join Date
    Mar 2005
    Location
    Bradford UK
    Posts
    1,708

    Resolved [RESOLVED] Jquery to PageMethods

    Code:
    <asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server" EnablePageMethods="true" EnablePartialRendering="true">
    </asp:ToolkitScriptManager>  <script language="javascript" type="text/javascript">
        $(function () {
            $(".mnuMainMenu_SkipLink a").each(function (index) 
                            { 
                                $(this).click(ClearCache(););
                            }
                         );
                         
                      }
        );
        
        function ClearCache() {
            PageMethods.ClearSearchCache();
        }
    </script>
    I am trying to make jquery find my asp.net menu and add a click event on each one that will call some server side script.

    However I keep getting the message Object expected. I am unable to tell whether it cant find my page method or my jquery is wrong?

  2. #2

    Thread Starter
    Frenzied Member FishGuy's Avatar
    Join Date
    Mar 2005
    Location
    Bradford UK
    Posts
    1,708

    Re: Jquery to PageMethods

    I simplyfied the function and still get the error

    Code:
    $(function () { $(".mnuMainMenu a").each(function (index) { $(this).click(function () { alert("fish");}); }); });
    I am basically trying to copy this tutorial and adapt it for my needs
    http://stackoverflow.com/questions/4...m-from-aspmenu

  3. #3
    PowerPoster Nitesh's Avatar
    Join Date
    Mar 2007
    Location
    Death Valley
    Posts
    2,556

    Re: Jquery to PageMethods

    it's probably trying to assign the click event before the DOM is ready. try putting that code inside the following function

    Code:
    $(document).ready(function() {
    
            });

  4. #4

    Thread Starter
    Frenzied Member FishGuy's Avatar
    Join Date
    Mar 2005
    Location
    Bradford UK
    Posts
    1,708

    Re: Jquery to PageMethods

    Ok I solved the original error, I wasnt referencing the jquery library correctly, however the I dont think my code is finding the menu items as the alert still doesnt present its self.
    I also added the code into the function as above.
    Code:
    <a href="#MainMenu_mnuMainMenu_SkipLink"><img alt="Skip Navigation Links" src="/WebResource.axd?d=_1nhm1HxiLCVEzCUEJg_xF7psxFSLCBcivpWJjmInnqGrey1YpUhgYK2XOZ684dF2-bOL7YIubQtVWwFBffiGONXTj41&amp;t=634376242957102069" width="0" height="0" style="border-width:0px;" /></a><div id="MainMenu_mnuMainMenu">
    	<ul class="level1">
    		<li><a title="Help" class="level1" href="/Help.aspx">help and faq</a></li>
    	</ul>
    </div><a id="MainMenu_mnuMainMenu_SkipLink"></a>

  5. #5

    Thread Starter
    Frenzied Member FishGuy's Avatar
    Join Date
    Mar 2005
    Location
    Bradford UK
    Posts
    1,708

    Re: Jquery to PageMethods

    After all that I got the jquery working but now it seems that PageMethods will not work when using Usercontrols or master pages, what a waste of time
    Code:
    <script type="text/javascript">
        $(document).ready(function () {
    
            $(function () { $("#MainMenu_mnuMainMenu").each(function (index) { $(this).click(function () { ClearCache(); return true; }); }); });
    
            function ClearCache() {
                alert("fishy");
                PageMethods.ClearSearchCache();
            }
        });
    
       
    </script>

  6. #6

    Thread Starter
    Frenzied Member FishGuy's Avatar
    Join Date
    Mar 2005
    Location
    Bradford UK
    Posts
    1,708

    Re: Jquery to PageMethods

    Ok its not as bad as expected most of the code i.e. the scriptmanager and the jquery can all go in the master page only the webmethod as below needs to go in the actual page and is apparently not allowed in the code behind. But could I just add a reference to it instead of repeating on each page?
    <script language="C#" runat="server">
    [System.Web.Services.WebMethod(CacheDuration = 60)]


    public static void ClearSearchCache()
    {
    SearchResults sContent = SearchResults.GetContent();
    if (sContent != null)
    {
    HttpContext.Current.Session.Remove("_SearchResults_");
    }
    }

    </script>

  7. #7
    ASP.NET Moderator gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: [RESOLVED] Jquery to PageMethods

    If that method wants to be on every page, then you could create a Base Page class which includes it, and have all your ASP.Net Page inherit from that Base Page class.

    Gary

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width