Click here to Skip to main content
11,802,205 members (53,626 online)
Rate this: bad
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 at 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 at 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
0 OriginalGriff 475
1 KrunalRohit 341
2 F-ES Sitecore 295
3 Afzaal Ahmad Zeeshan 230
4 CHill60 195
0 OriginalGriff 2,715
1 Maciej Los 1,900
2 KrunalRohit 1,797
3 CPallini 1,550
4 Richard MacCutchan 1,157

Advertise | Privacy | Mobile
Web04 | 2.8.151002.1 | Last Updated 22 Mar 2013
Copyright © CodeProject, 1999-2015
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