Click here to Skip to main content
13,087,566 members (93,500 online)
Rate this:
Please Sign up or sign in to vote.
I am built an mp3 player that loads songs up randomly. I have a function in the CodeBehind page that runs a SQL query to pull a random record. I call the function during the PageLoad, and it works great. I'm trying to add a button that calls the function again, but without refreshing the page. I'm using an image button.

I looked into AJAX solutions, but from what I found, so it the Web Method can't call my getNext function.

I am fairly confident that my issue does not lie in my code, but in my design. If someone has a good ideas to point me in the right direction, I would be grateful.
Posted 22-Mar-13 14:23pm

1 solution

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

Solution 1

//On Page

<asp:scriptmanager id="ScripManager1" runat="server" enablepagemethods="true" xmlns:asp="#unknown">


function SavePostions(object) {
PageMethods.SavePosition(object.attr('id'), object.position().left + "px", object.position().top + "px", object.css("height"), object.css("width"), function () { });


//Code Behind

public static void SavePosition(string id, string x, string y, string heght, string width)
//Do Your Thing
Motley Drew 22-Mar-13 21:12pm
I actually tried this. In the "Do your thing" spot, I put, getSong(). I get,
"An object reference is required for the non-static field, method or property 'SiteMaster.getSong()'"
S. M. Ahasan Habib 22-Mar-13 22:15pm
Seems you write the serverside method in the Masterpage. You must write it to Page codebehind. Event if you write that webmethod to the user control then it will not work. So you just create a page, then take ScriptMangager referenece to that page(either you do not take reference it from masterpage) then call webmethod which is written in that page code behind.

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web03 | 2.8.170813.1 | Last Updated 22 Mar 2013
Copyright © CodeProject, 1999-2017
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