Click here to Skip to main content
15,891,905 members
Please Sign up or sign in to vote.
4.00/5 (1 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

1 solution

//On Page

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

<script>

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

</script>




//Code Behind


[WebMethod]
public static void SavePosition(string id, string x, string y, string heght, string width)
{
//Do Your Thing
}
 
Share this answer
 
Comments
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)



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