Click here to Skip to main content
Rate this: bad
good
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 15:23pm

1 solution

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

Solution 1

//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
}
  Permalink  
Comments
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 270
1 Sergey Alexandrovich Kryukov 185
2 BillWoodruff 173
3 CPallini 155
4 Kamal Rocks 144
0 OriginalGriff 5,655
1 DamithSL 4,506
2 Maciej Los 3,997
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,180


Advertise | Privacy | Mobile
Web02 | 2.8.141216.1 | Last Updated 22 Mar 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